Skip to content

perf/streaming optimizations - #6

Merged
lcweden merged 7 commits into
mainfrom
perf/streaming-optimizations
May 22, 2026
Merged

perf/streaming optimizations#6
lcweden merged 7 commits into
mainfrom
perf/streaming-optimizations

Conversation

@lcweden

@lcweden lcweden commented May 22, 2026

Copy link
Copy Markdown
Owner

This pull request introduces several improvements and refactorings to the JSON streaming selector and encoding/decoding modules. The most significant changes include a major rewrite of the JSONTextSelectorStream class for efficiency, optimizations in the encoder with caching and streamlined decoding, and updates to constants for consistency and performance.

Stream Selector Refactor and Efficiency Improvements:

  • The JSONTextSelectorStream class in src/libs/stream-selector.ts has been completely rewritten to use internal state arrays for tracking depth, types, and indexes, and now interacts directly with a matcher for efficient JSONPath-like query evaluation. This results in faster and more memory-efficient streaming and filtering of JSON values. [1] [2]

Encoder Optimizations:

  • The Encoder class in src/modules/encoder.ts now uses a cache for commonly used encoded byte sequences (such as "null", "true", "false", indentation, and prefix), reducing repeated encoding operations and improving performance. [1] [2] [3]
  • All uses of decodeText in the encoder and decoder have been simplified to pass a boolean for the fatal option instead of an options object, making the code cleaner and more consistent. [1] [2] [3] [4] [5] [6] [7] [8]

Decoder Enhancements:

  • The Decoder class in src/modules/decoder.ts adds new methods needObjectName and lastObjectName to expose state needed for more efficient path matching and streaming. The skipValue method is now more robust and efficient, handling containers and literals directly. [1] [2] [3]

Constants and Type Consistency:

  • Constants in src/common/constants.ts have been updated: new ASCII codes have been added, numeric enums are now used for selectors and segments, and MAX_NESTING_DEPTH uses an underscore for readability. The UNICODE object is now as const for stricter typing. [1] [2] [3] [4]

API and Type Cleanups:

  • Minor cleanups include removing unused or redundant code, and ensuring that all exported constants and objects use as const for type safety and better TypeScript support.

These changes together improve performance, maintainability, and type safety across the JSON streaming and encoding/decoding pipeline.

@lcweden lcweden self-assigned this May 22, 2026
@lcweden lcweden added bug Something isn't working enhancement New feature or request labels May 22, 2026
@lcweden lcweden changed the title Perf/streaming optimizations perf/streaming optimizations May 22, 2026
@lcweden
lcweden merged commit f6797f1 into main May 22, 2026
1 check passed
@lcweden
lcweden deleted the perf/streaming-optimizations branch May 22, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant