Skip to content
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

Various modules: stringify and parse json is slow #11399

Open
patmmccann opened this issue Apr 25, 2024 · 5 comments
Open

Various modules: stringify and parse json is slow #11399

patmmccann opened this issue Apr 25, 2024 · 5 comments

Comments

@patmmccann
Copy link
Collaborator

patmmccann commented Apr 25, 2024

https://github.com/search?q=repo%3Aprebid%2FPrebid.js+json.parse%28json.stringify+path%3A%2F%5Emodules%5C%2F%2F&type=code is used by 17 modules. Several of these patterns can be improved similar to this example: InteractiveAdvertisingBureau/iabtcf-es#446

@patmmccann
Copy link
Collaborator Author

Reopening as we've had some success with the klona library we plan to commit

@patmmccann
Copy link
Collaborator Author

Cc @bbaresic

@dgirardi
Copy link
Collaborator

dgirardi commented Apr 29, 2024

JSON.parse + JSON.stringify used to be the fastest way to deep clone objects. Apparently it still is.

We are probably deep cloning when it's not needed, but it's often not trivial to verify when it isn't, and I don't think it makes sense to go after the most responsible way to do it. In general premature optimization is a bad idea, it should be focused on known (= measured) bottlenecks.

@bbaresic
Copy link
Contributor

Here is a benchmark that I did. It tries to mimic a Prebid object (several levels of nesting).

It is a micro-benchmark, and that comes with some caveats, but as seen there, klona outperforms everything.

I created a PR for it.

@patmmccann
Copy link
Collaborator Author

patmmccann commented Apr 30, 2024

@dgirardi Raptive measured some bottlenecks in just-clone, @bbaresic has already tested this change on live traffic to substantial improvement

We haven't converted any of the function calls in this issue over, just replaced the library import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants