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

Convert node blacklist to a Set for performance gains #433

Merged
merged 1 commit into from
May 18, 2024

Conversation

husainalzeera
Copy link
Contributor

The node code is currently going through the blacklist array through an indexOf call. By converting it to a Set and using has there is a significant performance gain.

The node code is currently going through the blacklist array through an `indexOf` call. By converting it to a Set and using `has` there is a significant performance gain.
@VasilNikolov
Copy link

We can think of implementing an async version of the functions too, possible performance benefits since it won't block the thread.

@lyrixx
Copy link
Collaborator

lyrixx commented Mar 12, 2024

I understand it's much faster when looking int the set,but initialization is slower, isn't?

Can you share some bench?

thanks

@alcore
Copy link

alcore commented May 8, 2024

@lyrixx

Can you share some bench?

It's a O(n) change to O(1), with an N of 55k+, where the initialization cost is paid only once, as opposed to the runtime cost. You can expect a difference of at minimum several orders of magnitude (I'd assume a 50-100x speedup). Initialization is O(n) in both cases, the difference will be neglible in comparison.

Do you really need a benchmark for something this obvious?

For the record, the Rust version (possibly others too) suffers from the exact same issue and would massively benefit from a PHF Set/Map instead. With that change, and getting rid of all the entirely unnecessary allocations, I got a 2000x speedup (111.408µs vs 52ns) on a test address composed of 4 test segments ("test.test.test.io"), where the difference becomes even more pronounced the more segments you have.

@VasilNikolov

We can think of implementing an async version of the functions too, possible performance benefits since it won't block the thread.

There is literally nothing "blocking the thread" other than work that must happen anyway. Slapping "async" on code that is purely synchronous will in fact give you not a single benefit in any respect, because no "performance benefits" are "possible" in a single-threaded context that needs to perform those operations anyway.

If anything, async here will decrease performance and add complexity on top.

This is a common bad practice in ecosystems with async/await - please don't propagate it.

@VasilNikolov
Copy link

@alcore Yes, async is pointless here, dk what I was thinking.

@FGRibreau FGRibreau merged commit 9c16324 into FGRibreau:master May 18, 2024
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

5 participants