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

feat: improve dataValidation function #5860

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Blakko
Copy link
Contributor

@Blakko Blakko commented Jun 12, 2024

From my tests on a 3k nodes graph, the execution time of this function went from 400ms down to 1ms

Copy link
Contributor

@Aarebecca Aarebecca left a comment

Choose a reason for hiding this comment

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

Although it is faster to using for than map loop, there shouldn't be such a large gap at 3k nodes

packages/core/src/util/validation.ts Outdated Show resolved Hide resolved
@Blakko
Copy link
Contributor Author

Blakko commented Jun 12, 2024

The performance gain comes from changing
ids.includes(edge.source) || !ids.includes(edge.target)
into
return !ids.has(edge.source) || !ids.has(edge.target);

I'll test removing the for loops in favor of a .each line, I agree there shouldn't be a big difference

@Blakko
Copy link
Contributor Author

Blakko commented Jun 12, 2024

Using a forEach to populate the set (rather than the for loop) did show a negligible performance impact, so I made the code tidier

@Aarebecca
Copy link
Contributor

It looks like there's something wrong with ci in v4 and this PR will be merged after we fix it

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.

None yet

2 participants