-
Notifications
You must be signed in to change notification settings - Fork 37
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
extractBytesLiteral overhead due to Bytes parameter (and shared_ptr usage) #1910
Comments
Uh.. @rsmmr - let me just piggy back. Taking a flamegraph of 10-10.spicy, the |
Uhm, the following patch improves performance of this particularly reproducer ~3-4x. Doesn't seem like there's anything wrong with it, is there? The issue with the extra Bytes allocation continuous to exists, but this should fix some of the obvious shared_ptr overhead.
|
Oh, good catch! I'll play a bit that, seems to make quite a difference indeed. |
We now create the bytes instance representing the literal as a global singleton to avoid instantiating it over and over again. Closes #1910.
We now create the bytes instance representing the literal as a global singleton to avoid instantiating it over and over again. Closes #1910.
We now create the bytes instance representing the literal as a global singleton to avoid instantiating it over and over again. Closes #1910.
* origin/topic/robin/gh-1910-parse-literal: Replace our poor hash function with `std::hash()`. Add infrastructure to create and cache global constants. Polish code a bit for readability. Avoid redundant computation during literal parsing. Optimize parsing of literal bytes. Introduce `UnsafeConstIterator` for bytes instances.
As discussed on #1909, here's a microbenchmark showing that parsing a bytes literal becomes significantly slower when the literal's size exceeds the threshold for short-string-optimization (15 with clang/gcc on my system). Essentially, there's a std::string initialization in a potentially hot path (any unit containing a bytes literal hits this path). Eve with SSO in effect for small literals, there's overhead due to copying the characters into the Bytes (std::string).
It seems a call to extractBytesLiteral should either pass a string_view for the literal to avoid the initialization of the Bytes instance, or take a reference to a statically allocated Bytes instance to avoid this unneeded overhead.
Summary of the examples:
test-20.spicy
should parse at least as fast astest-10-10.spicy
, not 1.13x slower. Note also they all use skip, so there's even less reason for the difference.Starting with the following module, test-10 4*10 bytes.
Moving to the following two variants, parsing 2 * (16 + 4) and 2*20 bytes
And further
Runner:
The text was updated successfully, but these errors were encountered: