prebid / Prebid.js

Setup and manage header bidding advertising partners without writing code or confusing line items. Prebid.js is open source and free.

Home Page:https://docs.prebid.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Various modules: stringify and parse json is slow

patmmccann opened this issue · comments

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

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.

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.

@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