-
Notifications
You must be signed in to change notification settings - Fork 45
fix perf in json parsing logic #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improves performance in JSON parsing logic by utilizing modern browser features and optimizing regular expression patterns for handling BigInt values in JSON serialization/deserialization.
- Updates JSON parsing logic to use native
JSON.rawJSONwhen available (Node 20.12+, Chrome 114+) - Replaces complex regex patterns with more efficient string/number matching
- Adds noise value handling to prevent conflicts with the custom BigInt format
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/core/json.ts | Refactored JSON serialization/parsing logic with performance optimizations and modern API support |
| jest.config.mjs | Added transform configurations for Jest test environments |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (Array.isArray(replacer) && replacer.includes(key)) { | ||
| return val; | ||
| } | ||
|
|
||
| return val; |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When replacer is an array, the logic is inverted. According to JSON.stringify spec, when replacer is an array, only properties with keys included in the array should be serialized. Currently, it returns the value when the key is included but also returns the value unconditionally at the end, making the array check ineffective.
| if (Array.isArray(replacer) && replacer.includes(key)) { | ||
| return val; | ||
| } | ||
|
|
||
| return val; |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When replacer is an array, the logic is inverted. According to JSON.stringify spec, when replacer is an array, only properties with keys included in the array should be serialized. Currently, it returns the value when the key is included but also returns the value unconditionally at the end, making the array check ineffective.
No description provided.