-
Notifications
You must be signed in to change notification settings - Fork 115
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
Mint's downcase_ascii/1
is slower than String.downcase(str, :ascii)
#420
Comments
@IceDragon200 thanks for the issue and the detailed report! 💟 Interesting. One thing from your benchmarks is that the memory usage difference is wild, with Mint basically using no memory compared to It boils down to how these are implemented: Mint does a Out of curiosity, could you please benchmark this implementation? def downcase_ascii(<<char, rest::binary>>) do
<<downcase_ascii_char(char), downcase_ascii(rest)>>
end
def downcase_ascii(<<>>) do
<<>>
end
def downcase_ascii_char(char) when char in ?A..?Z, do: char + 32
def downcase_ascii_char(char), do: char |
downcase_ascii/1
is slower than String.downcase(str, :ascii)
Had to adjust your code a tad bit, otherwise it wouldn't run: def downcase_ascii(<<char, rest::binary>>) do
<<downcase_ascii_char(char), downcase_ascii(rest)::binary>>
end
def downcase_ascii(<<>>) do
<<>>
end
def downcase_ascii_char(char) when char in ?A..?Z, do: char + 32
def downcase_ascii_char(char), do: char The error for future reference without
And the results (with patch):
Conclusion: Please don't use that |
LOL ok yep, that's crazy banana pants. Ok, so it looks like we can optimize for speed, gaining 30-40% on single-digit µs times, or memory, with what looks like a huge reduction in memory usage. At the same time I’m skeptical of this reduction in memory, seems a bit too good to be true. @ericmj thoughts? |
If it's not faster then I am all for removing the code. @IceDragon200 Thanks for benchmarking this. Would you like to send a PR that replaces the function with |
@ericmj PR created, now pending review |
Despite touting:
The only thing it beats good old String.downcase(&1, :ascii) on is memory usage:
I only bring this up as I investigate some poor http2 performance (the same request completes in 1ms for http1, but takes 43ms for http2, even when reusing connections), unsure if it's mint or cowboy at this point (hard to find a good http2 client/server to compare against locally)
But I found that and it kind irked me.
My only question: what is mint's "efficiency" goal here, is it performance or memory usage?
The text was updated successfully, but these errors were encountered: