-
Notifications
You must be signed in to change notification settings - Fork 11
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
Performance #15
Comments
2 things here are causing the extra allocations. This slice should preallocate some reasonable amount. func (ac AhoCorasick) FindAll(haystack string) []Match {
.......
matches := make([]Match, 0) And the fact that every search is returning a |
I tried replacing references to Match with Match by value throughout the code, which reduced heap allocations by 10. (This is related to heap escapes.) However, the CPU performance is still about twice as bad compared to the Cloudflare implementation. |
Did you also give the slice allocation a good cap? Maybe? matches := make([]Match, 0, 32) Try it and if it doesn't work, i'll take a look this weekend. |
No it will not work as planned: |
Hi, I've run simple benchmark for cloudflare and your implementations:
And on Mac M1 Pro I've got the following results:
It looks like the performance is twice as bad compared to the Cloudflare implementation,
with 29 allocations vs 5. Could you check please?
The text was updated successfully, but these errors were encountered: