Skip to content

feat: add memoization to when converting a graph into a tree #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 1 commit into from
Nov 26, 2020

Conversation

admons
Copy link
Contributor

@admons admons commented Nov 25, 2020

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

It adds memoization in the graphToDepTree
This will result in reused objects in a tree instead, for example the following graph

A --> B --> D
  \-> C --> B

Instead of creating B --> D twice (as today), it will reuse the B subtree

@admons admons requested review from darscan and orsagie November 25, 2020 16:07
@admons admons requested a review from a team as a code owner November 25, 2020 16:07
@FauxFaux
Copy link
Contributor

Does this just allocate forever?

@admons
Copy link
Contributor Author

admons commented Nov 25, 2020

Does this just allocate forever?

No, it's a scoped function, GC will clean memoizationMap.

function a(b = new Map()) { return b; }
assert.notEqual(a(), a()); // true

@robcresswell
Copy link
Contributor

This looks cool @admons! Any idea on the impact?

@admons
Copy link
Contributor Author

admons commented Nov 26, 2020

@robcresswell thanks :)

  1. This will create trees that today would get stuck and won't be generated (i.e. root -> 100,000 children -> all pointing to a specific node "B" -> 50,000 children)
    For those trees, the problem will be on the serialisation phase (if needed)
  2. In case that we have a code (in another library/service) that mutate a specific node in a tree, if this node is reused, there will be side affects

@robcresswell
Copy link
Contributor

@admons Ah sorry I should've been more specific. I got the overall idea; I meant rather if you'd been able to benchmark anything. Just out of curiosity than anything else 🤓

@admons
Copy link
Contributor Author

admons commented Nov 26, 2020

@robcresswell :)
I have a DepGraph of the cockroachDB and its an enormous graph see here
More than 15 minutes of 100% cpu to convert this depgraph still wasn't enought
After adding this change, it took 88ms

@robcresswell
Copy link
Contributor

Niiice, thats what I wanted to hear 🤓

@admons admons force-pushed the feat/memoization-in-graph-to-dep-tree branch from 9246e26 to edf048f Compare November 26, 2020 11:47
@admons admons force-pushed the feat/memoization-in-graph-to-dep-tree branch from edf048f to 113746f Compare November 26, 2020 12:16
@darscan
Copy link
Contributor

darscan commented Nov 26, 2020

🎉

@admons admons merged commit 56a66e3 into master Nov 26, 2020
@admons admons deleted the feat/memoization-in-graph-to-dep-tree branch November 26, 2020 13:04
@snyksec
Copy link

snyksec commented Nov 26, 2020

🎉 This PR is included in version 1.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants