perf/streaming optimizations - #6
Merged
Merged
Conversation
…d optimizing decoder functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
JSONTextSelectorStreamclass 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:
JSONTextSelectorStreamclass insrc/libs/stream-selector.tshas 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:
Encoderclass insrc/modules/encoder.tsnow 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]decodeTextin the encoder and decoder have been simplified to pass a boolean for thefataloption instead of an options object, making the code cleaner and more consistent. [1] [2] [3] [4] [5] [6] [7] [8]Decoder Enhancements:
Decoderclass insrc/modules/decoder.tsadds new methodsneedObjectNameandlastObjectNameto expose state needed for more efficient path matching and streaming. TheskipValuemethod is now more robust and efficient, handling containers and literals directly. [1] [2] [3]Constants and Type Consistency:
src/common/constants.tshave been updated: new ASCII codes have been added, numeric enums are now used for selectors and segments, andMAX_NESTING_DEPTHuses an underscore for readability. TheUNICODEobject is nowas constfor stricter typing. [1] [2] [3] [4]API and Type Cleanups:
as constfor type safety and better TypeScript support.These changes together improve performance, maintainability, and type safety across the JSON streaming and encoding/decoding pipeline.