-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Follow up to #44261: string_id performance and correctness #44398
Merged
ZhilkinSerg
merged 4 commits into
CleverRaven:master
from
Aivean:generic_factory_string_id_improvements
Sep 25, 2020
Merged
Follow up to #44261: string_id performance and correctness #44398
ZhilkinSerg
merged 4 commits into
CleverRaven:master
from
Aivean:generic_factory_string_id_improvements
Sep 25, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
improve string_id comparison performance when `_version`s match add catch2 benchmarks and unit tests for string_id
Aivean
force-pushed
the
generic_factory_string_id_improvements
branch
from
September 24, 2020 18:26
9096ea0
to
be16e37
Compare
jbytheway
reviewed
Sep 24, 2020
enable `CATCH_CONFIG_ENABLE_BENCHMARKING` permanently disable benchmark tests on one-by-one basis by default
ZhilkinSerg
reviewed
Sep 25, 2020
ZhilkinSerg
reviewed
Sep 25, 2020
@@ -15,6 +15,9 @@ ODIR ?= obj | |||
|
|||
LDFLAGS += -L. | |||
|
|||
# Enabling benchmarks | |||
DEFINES += -DCATCH_CONFIG_ENABLE_BENCHMARKING |
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.
CATCH_CONFIG_ENABLE_BENCHMARKING
should be also added to VS project (I've did this for you).
ZhilkinSerg
added
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Performance
Performance boosting code (CPU, memory, etc.)
labels
Sep 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Performance
Performance boosting code (CPU, memory, etc.)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Infrastructure "Improve string_id comparison performance, add unit test and benchmarks"
Purpose of change
Follow up to #44261, improvements were suggested by @kevingranade and @jbytheway :
string_id::_version
64 bitversion
overflows and wraps aroundDescribe the solution
Implemented suggestions regarding
version
. In addition:Describe alternatives you've considered
I was also thinking about the case when one or both string_ids that participate in equality check have outdated version.
For example, this might happen when one string_id is static const that is used only for comparison with some dynamic entities.
In such case it would make sense to update cache of both ids (by invoking
string_id::id()
method) before comparison. However, currentlystring_id::id()
is optional and might not exist. I'm not sure if there is some C++ template magic that can check in compile time whetherstring_id::id()
is implemented for particular string_id type so we can have differentstring_id::operator==
implementation depending onstring_id::id()
existence.A simpler approach would be to manually override
string_id::operator==
for string_id types wherestring_id::id()
is defined and add cache update there.Currently I've added commented out
CATCH_CONFIG_ENABLE_BENCHMARKING
definition to theCMakeLists.txt
andMakefile
. Probably it would be better to have it enabled conditionally as an option or a build parameter. Would it be appropriate to add a global option to cmake build, something like "BENCHMARKS"? I'm not sure about that, because this option only makes sense for the test build.Testing
Checked that game compiles and works.
Added unit tests that check string_id equality correctness in all possible scenarios.
Additional context
I've benchmarked the performance of
string_id::obj
lookup with 32bit and 64bit version and the difference was within the error margin.Also, below are benchmark results for string comparison before and after change:
Before
After:
Conclusion:
Before the change, on my machine, depending on the string length, string_id comparison took 6-7ns for short strings, and 12-15 ns for long strings.
After the change, there was no significant overhead when comparing string ids with outdated version, but when versions are valid, comparison time drops to 1.7-2ns regardless of the string length (i.e. 3x-6x speedup).