-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Replace StaticStringMap with far more optimized version #21498
base: master
Are you sure you want to change the base?
Conversation
be28052
to
4de75ff
Compare
impressive results! can you post the benchmark(s) source code and also expose a version that lets |
08a1339
to
6ce870d
Compare
Why remove the initComptime() and init() API? The idea behind #19719 was to move kvs_list from a type param to a init() param in order to avoid very long type names which result from them being a type param. EDIT: I like the simplicity of this implementation and the results seem to speak for themselves 👍 . FWIW, I don't care about runtime init(). But I think keeping the StaticStringMap name and moving kvs_list to an initComptime() param might be preferrable. |
Thank you for explaining the original reasoning! It's well founded. - I'll work on that and see how soon I can get it working. What are your thoughts on replacing |
034277d
to
56b7655
Compare
e24762b
to
67e31c5
Compare
Seems like the x86_64 backend hasn't implemented gte vector comparison yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive results.
Please document the breaking changes in the PR writeup (pretend you are writing release notes).
Please also explain why you deleted a lot of test coverage, otherwise it's difficult to be sure these changes don't break existing use cases.
Sounds good - let me know if you would like further changes. |
c5b9e07
to
d60e6d1
Compare
c90a8b0
to
d93419d
Compare
I updated the simple benchmarking code: |
i started a review pointing out an issue in toLowerSimd but it doesnt seem to be working so I'll post it here:
this has two issues: is_upper incorrectly identifying [0, 65) as being uppercase letters, and - const true_vec: BVec = @splat(true);
- const is_upper: BVec = @select(bool, at_min, at_max, true_vec);
+ const false_vec: BVec = @splat(false);
+ const is_upper: BVec = @select(bool, at_min, at_max, false_vec);
- const lowered: SVec = input + @as(SVec, @splat('a' - 'A'));
+ const lowered: SVec = input +% @as(SVec, @splat('a' - 'A')); comptime code to verify that the changed version works |
7eaa51d
to
98ec4a0
Compare
I understand that this PR removes 3 things -
I am confident that the last two points are useless and wouldn't cause mass community outrage if removed, but I am not entirely sure about the first point. While I couldn't find any uses of StaticStringMap where the key/value pairs weren't comptime, My searching doesn't mean that use-cases don't exist. I am happy closing this PR if it is deemed that the feature culling is a significant downside. In case it is not though, what tweaks should I make to this PR to improve the quality? Wondering if there is anything that can be done to improve it, or even cut out more unnecessary features. |
This feature is relatively new, and as I understand it, was mostly a side-effect of other changes in #19719. That is, it wasn't motivated by a particular use case, but was instead just added because it was now possible to provide (correct me if I'm wrong, @travisstaloch). |
That is correct. I don't think removing runtime init() is or the getLongestPrefix() functions is going to be a big deal. They were only added as extra, maybe nice to haves. And getLongestPrefix() was doing a linear scan so its probably better to remove it. |
f40e2a3
to
3d6e6ef
Compare
I finally learned how to use git, and resolved that pesky rebase conflict, squashing my changes into one commit. If this issue warrants some release notes, the commit message is a good resource. Please let me know if there is something different that should be done for this PR. |
3d6e6ef
to
0143320
Compare
I'm pretty sure the failures are unrelated, but I am curious about the aarch64-linux-release failure. Looks like it is incremental related. Is this test nondeterministic by any chance? |
My working theory for our inconsistent CI failures is that some system condition when under load causes processes to frequently crash. That aligns with what we see here -- note that on the failed incremental test, we also get a It's possible there is an incremental test case which is sometimes crashing the compiler, but I'd have to see the crash on a I'll re-run the failed jobs when the in-progress one finishes. EDIT: oh, that incremental test totally is actually flaky, my bad -- see this run. Will fix now! |
StaticArrayMap and StaticArrayMapWithEql are more alternatives to StaticStringMap and StaticStringMapWithEql, the difference being that they can have an array of any type of uniquely represented data as the key, rather than just an array of u8. StaticStringMapIgnoreCase has been added to provide a case-insensitive definition of StaticArrayMap. While you *can* use StaticArrayMapWithEql, StaticStringMapIgnoreCase is a common usecase of StaticStringMap while also being optimized with SIMD. The construction of StaticStringMap (provided by StaticArrayMap) has changed to be comptime-only. This change allows us to greatly improve the generated machine code through sorting the keys by length and comparing multiple bytes at the same time. The breaking changes include: - StaticStringMapWithEql interface has changed - specifically, take a look at the function interface of the eql function, which now takes a comptime-time known length, a comptime-time known array of an expected key, a runtime-known array of the recieved key, and returns a boolean indicating whether the two classify as matching. - The getLongestPrefix and getLongestPrefixIndex functions have been removed. They did not see much use. As a result of these changes, performance is greatly improved. If you have been using a runtime initialization of a StaticStringMap, consider using comptime initialization or std.StaticStringMap. Many test cases depended on getLongestPrefix, getLongestPrefixIndex, or runtime initialization. Those test cases have been removed, as they are no longer testing existing code.
0143320
to
86bf50c
Compare
Optimized StaticStringMap & Introduction of StaticArrayMap
New Features:
std.StaticArrayMap
andstd.StaticArrayMapWithEql
have been added. They provide an optimized static mapping from arbitrary slice types to values.std.StaticStringMapIgnoreCase
has been added. It is a handy case-insensitive static string map.Changes:
std.StaticStringMapWithEql
: Theeql
function interface has changed - it takes a comptime-known array length, one comptime known key array, and one runtime-known key array.init()
function has been removed. Please useinitComptime()
if possible. For use-cases where key/value pairs may only be known at runtime,std.StringHashMap
may be a good alternative to the old behavior.getLongestPrefix
andgetLongestPrefixIndex
functions have been removed. Originally added to see if they would be useful, they did not see much use.Performance:
Raw
StaticStringMap
performance forget
andhas
operations has tripled:Test cases were modified or removed based on whether they were testing the removed runtime-known key/value initialization,
getLongestPrefix
, orgetLongestPrefixIndex
.