-
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
bytes for loop performance #1663
Comments
I think the more general issue is that iterations over collections of known size can be expensive since we always emit checks at runtime; in general this makes sense since even with a range To be faster we would need a way to detect that the collection itself is not modified. This is non-trivial to do automatically since we'd have to make sure that all called code does not modify the collection (e.g., change element order, or remove them); this could even happen in e.g., called functions (which do not even need to be implemented in Spicy, so we might be unable to inspect their bodies). I think we talked in the past about collection methods like If such iteration is a bottleneck for you right now you could implement a custom C++ function which uses unchecked iteration after making sure you can uphold the invariants required for that. |
In the context zeek/zeek#3580 it was observed that a
for
loop over a bytes object to xor decode the content takes ~30% of the total runtime in that setting. This ticket is meant as a generic "speed up bytes iteration".The test is iterating 500k times over a 134 bytes instance in
%init
. The SPICY_THREADED=1 version creates a short lived thread in spicy-driver's main to avoid glibc using an optimized non-atomic shared_ptrs (#1600) This reflects better the performance within an application like Zeek and makes performance significantly worse. Python is added as baseline which executes significantly faster.No sure how relevant this is, for looping over large bytes might not be a common use case.
echo "x" | ../build/bin/spicy-driver loop.hlto
echo "x" | SPICY_THREADED=1 ../build/bin/spicy-driver loop.hlto
python3 loop.py
The non-dwarf flamegraph (suspect std::shared_ptr above the flat bars like in zeek/zeek#3580).
The text was updated successfully, but these errors were encountered: