Skip to content

Conversation

@Skn0tt
Copy link
Collaborator

@Skn0tt Skn0tt commented Aug 6, 2025

Closes #319

@Skn0tt Skn0tt requested review from Copilot and flybayer August 6, 2025 08:56
@Skn0tt Skn0tt self-assigned this Aug 6, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an optional inPlace parameter to the deserialize method that allows deserialization to mutate the original JSON object instead of creating a copy. The parse method is also updated to use in-place deserialization by default.

  • Added optional inPlace parameter to the deserialize method
  • Modified parse method to use in-place deserialization for performance optimization
  • Added test coverage for the new in-place deserialization functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/index.ts Added inPlace option to deserialize method and updated parse to use it
src/index.test.ts Added test case to verify in-place deserialization behavior

Comment on lines 84 to +85
parse<T = unknown>(string: string): T {
return this.deserialize(JSON.parse(string));
return this.deserialize(JSON.parse(string), { inPlace: true });
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parse method to use inPlace: true by default is a breaking change that could affect existing users who rely on the original JSON object remaining unmodified. Consider making this configurable or documenting this behavior change prominently.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, Copilot. JSON.parse is creating the object and it's safe to mutate it in place, because no other caller has access to it.

@Skn0tt Skn0tt mentioned this pull request Aug 6, 2025
flybayer
flybayer previously approved these changes Aug 6, 2025
Copy link
Member

@flybayer flybayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just need do update the API docs

@Skn0tt
Copy link
Collaborator Author

Skn0tt commented Aug 7, 2025

inPlace should probably be on by default if it weren't a breaking change, so I added into the main example.

@flybayer
Copy link
Member

flybayer commented Aug 7, 2025

I was meaning we should document the inPlace property and what it does in the #api section of the readme

@Skn0tt
Copy link
Collaborator Author

Skn0tt commented Aug 11, 2025

That's what I did, no?

@Skn0tt Skn0tt merged commit 1396ca8 into main Aug 13, 2025
0 of 4 checks passed
@Skn0tt Skn0tt deleted the in-place-deserialize branch August 13, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance: Redundant deep copy in parse()deserialize() flow accounts for ~80% of deserialization time

3 participants