-
Notifications
You must be signed in to change notification settings - Fork 444
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
Introduce string map class and switch to it #4774
Conversation
For the downstream testcase the compile time changes from:
down to:
So we are having nice 10% speedup. Two things contribute to this change:
|
f78ad80
to
099b9bf
Compare
Or we could just always use |
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.
For now, I went through the data structure implementation. Thank you for your contribution!
Yes. |
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.
Few nitpicks in the map implementation.
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.
A few comments for the rest of the code. Once we have C++20, we should try to revisit if we can replace the overloads that are the same for cstring
and std::string_view
with a single one taking a concept that is either. But I am not sure if GCC 9.2 has enough concepts support to allow that or if we would need to wait until we can drop it.
frontends/p4/checkNamedArgs.cpp
Outdated
@@ -21,7 +21,7 @@ namespace P4 { | |||
bool CheckNamedArgs::checkArguments(const IR::Vector<IR::Argument> *arguments) { | |||
bool first = true; | |||
bool hasName = false; | |||
std::map<cstring, const IR::Argument *> found; | |||
absl::flat_hash_map<cstring, const IR::Argument *> found; |
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.
Should we use the hasher from Utils
?
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.
It will be used via our std::hash
specialization. So, nothing special is needed. Though, abseil on top would salt the hash, so the iteration order will be randomized. I do not have preferences which approach is better.
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.
After thinking about this a bit more, maybe we can adopt the following rule:
- For local maps (within the method, etc) we can use
Util::Hash
directly. This way we won't have additional random salt on top of the existing hash, so the hashing latency will be reduced. - For members we'd stick with absel's randomized hashes. This way the iteration order will be different on each invocation. As a result, all possible accidentally added iterations could be noticed much earlier.
What do you think?
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.
So, I implemented this approach for local maps. Also, found one "funny" case when we had map cstring -> ID
which I replaces with set.
How does the performance compare to hvec_map? |
Its performance was lower in my initial tests. Checked once again to ensure we're comparing apples-to-apples replacing declaration map in
|
Rebased after #4780 merged |
c0a2be1
to
d3cd689
Compare
…ing, ...>: - Underlying map is abseil's unordered map - Supports heterogenous lookups with std::string_view keys - Several ordered_map<cstring, ...> bugs are fixed Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
Signed-off-by: Anton Korobeynikov <[email protected]>
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.
LGTM
The main change of this PR is a new
string_map<V>
class that doesordered_map<cstring, V>
but in a proper way:std::string_view
keys) is supported. Special care is done not to create cstrings in case if they are not in the map alreadystd::list
, similar toordered_map
. Likely we'd need to allowstd::vector
/absl::inlined_vector
as storage as well via dedicated policy, but I need to collect more statistics on thisGive this class, I moved two main users of
ordered_map<cstring, V>
to it:trying to refactor & modernize the API to allow & use heterogenous lookup as well.
While there I checked all instances of
std::map<cstring, something
in frontend / midend and replaced them with unordered maps where appropriate.While it might look like a breaking change, it is not. Even more, the code eases adopting of downstream code to explicit
const char* => cstring
conversion, as heterogenous lookup makes these conversions unnecessary. I moved code in backends to this where appropriate.Fixes #4763