Skip to content
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

Defer the call to get timer resolution until needed #2440

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

kccqzy
Copy link
Contributor

@kccqzy kccqzy commented Jan 14, 2025

We have a use case where the highway library is linked into a shared object. Currently whenever it is dlopen'ed, the static initializer runs including running the platform::TimerResolution. This has been observed in profiling and raised some questions, namely it shouldn't be necessary to initialize the benchmarking code if we are using the highway library but not to benchmark anything.

Furthermore, doing so is against many companies' C++ guidelines, making this a blocker for inclusion into companies' code bases.

This commit changes this variable from a namespace-scope static variable into a static local variable.

Copy link

google-cla bot commented Jan 14, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

We have a use case where the highway library is linked into a shared object.
Currently whenever it is dlopen'ed, the static initializer runs including
running the `platform::TimerResolution`. This has been observed in profiling and
raised some questions, namely it shouldn't be necessary to initialize the
benchmarking code if we are using the highway library but not to benchmark
anything.

Furthermore, doing so is against many companies' C++ guidelines, making this a
blocker for inclusion into companies' code bases.

This commit changes this variable from a namespace-scope static variable into a
static local variable. It may have a little bit more overhead but it should be
negligible.
@kccqzy kccqzy force-pushed the timer-resolution-defer-2 branch from 84314ad to cd56bbc Compare January 14, 2025 15:13
Copy link
Member

@jan-wassenberg jan-wassenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I agree this is an improvement.
FWIW our Bazel build has nanobenchmark as a separate optional build target/dependency, but in CMake it's unfortunately bundled together with the hwy files.

I had a quick look for other non-local static objects and did not see any.

@copybara-service copybara-service bot merged commit 7cccd1b into google:master Jan 15, 2025
5 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants