Skip to content

perf: remove unnecessary cloning and iteration #73

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

Merged
merged 18 commits into from
Nov 7, 2023

Conversation

jeswr
Copy link
Contributor

@jeswr jeswr commented Oct 29, 2023

This PR:

  1. Fixes a bug where cached document contexts were being mutated if they were being loaded via in @import statement (fix: deep copy imported contexts #71 was originally opened to resolve this).
  2. Removes all deep cloning to improve performance (perf: no deep cloning #72 was originally opened to resolve this)
  3. Skips applying idempotent operations to the parent.

All unit & spec tests in the jsonld-streaming-parser pass with these changes (tested against bce9e05).

I have also done a (small) benchmark of these changes. As can be seen the time taken to parse a context with these changes significantly decreases (in particular it is now 20x faster to parse a VC context).

Before:
Parse a context that has not been cached; and without caching in place x 78.17 ops/sec ±0.73% (78 runs sampled)
Parse a context object that has not been cached x 2,280 ops/sec ±0.65% (91 runs sampled)

in #72:
Parse a context that has not been cached; and without caching in place x 123 ops/sec ±0.78% (84 runs sampled)
Parse a context object that has not been cached x 5,417 ops/sec ±0.70% (87 runs sampled)

After (in this PR):
Parse a context that has not been cached; and without caching in place x 1,714 ops/sec ±0.78% (84 runs sampled)
Parse a context object that has not been cached x 8,902 ops/sec ±0.70% (87 runs sampled)

Let's get this merged and then I'll revisit #70 to see what is actually worth caching.

@jeswr jeswr mentioned this pull request Oct 29, 2023
@coveralls
Copy link

coveralls commented Oct 29, 2023

Pull Request Test Coverage Report for Build 6706243153

  • 53 of 53 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 6492290900: 0.0%
Covered Lines: 553
Relevant Lines: 553

💛 - Coveralls

@jeswr jeswr changed the title perf: no unnecessary parent calc perf: remove unnecessary cloning and iteration Oct 29, 2023
Copy link
Owner

@rubensworks rubensworks left a comment

Choose a reason for hiding this comment

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

Nice optimization work @jeswr!

@jeswr jeswr requested a review from rubensworks October 30, 2023 17:17
@jeswr jeswr requested a review from rubensworks October 31, 2023 12:09
@rubensworks rubensworks merged commit 28596b5 into rubensworks:master Nov 7, 2023
@rubensworks
Copy link
Owner

Impressive work @jeswr!
Released as 2.4.0.

@jeswr jeswr deleted the perf/no-unnecessary-parent-calc branch November 7, 2023 11:53
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.

3 participants