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

Cache the local time zone calculation on Windows #1791

Closed
wants to merge 1 commit into from

Conversation

malkia
Copy link

@malkia malkia commented Nov 25, 2024

On Windows 10+, combase.dll gets loaded, unloaded, then subsequently various COM-related functions called to initialize/deinitialize the system leading to performance degradation #1760

This "fix" here caches the value once. Obviously this won't work for long running apps, so ideally some kind of way knowing when to update the value are needed (like subscribing to time zone changes, or simply refreshing the value every once in a while).

In the mean time, this affects grpc for Windows where if grpc returns anything else than grpc::Status::OK it'll have to call this function. For processes running into grpc issues this means extra time added. It's also not a thing that normally would be caught, and I could not find benchmark for this case.

grpc/grpc#37766

Copy link
Member

@derekmauro derekmauro left a comment

Choose a reason for hiding this comment

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

A couple things.

Changes to this code must be send to https://github.com/google/cctz. We automatically import this code from there.

However, I'm not sure the changes would be accepted. I am a maintainer of CCTZ but I usually defer to @devbww if he has an opinion on CCTZ code. In general though I think gRPC should be caching absl::LocalTimeZone() and passing that to absl::FormatTime(). As I think you understand from the text of this pull request, the local time zone can change while the program is running and caching would defeat that and may do something unexpected.

Also note that Abseil's logging library caches the local time: https://github.com/abseil/abseil-cpp/blob/c7cf999bda8390d2dd294ef903716a80135e6f4c/absl/log/initialize.cc

}

static std::string& cached_win32_local_time_zone() {
static std::string cached_time_zone = get_once_win32_local_time_zone();
Copy link
Member

Choose a reason for hiding this comment

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

Note that this is not safe for global destruction. See https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables.

Copy link
Author

Choose a reason for hiding this comment

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

Good point! I wonder what else can be done here - maybe leaking the object? (Not ideal)

Copy link
Member

Choose a reason for hiding this comment

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

Yes that is what I would do, but I was just pointing that out. I think the approach here is wrong anyway. See above.

@malkia malkia closed this Dec 2, 2024
@malkia
Copy link
Author

malkia commented Dec 2, 2024

Per @derekmauro 's comment - closing this as it needs to be really cached in grpc not "fix" it here (or in cctz).

@devbww
Copy link

devbww commented Dec 4, 2024

I usually defer to @devbww if he has an opinion on CCTZ code. In general though I think gRPC should be caching absl::LocalTimeZone() and passing that to absl::FormatTime().

I agree with Derek, and just made a comment to that effect on grpc/grpc#37766, for what that's worth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants