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

Implement TZInfo.eager_load! #129

Closed
wants to merge 1 commit into from
Closed

Conversation

casperisfine
Copy link

We recently instrumented our application to locate the source of the constant cache bumps we were seeing, and tzinfo came up as one of the sources.

In production environment, it's detrimental for performance to use lazy loading. It's much better to load everything upfront as part of boot.

We recently instrumented our application to locate the
source of the constant cache bumps we were seeing, and tzinfo
came up as one of the sources.

In production environment, it's detrimental for performance to
use lazy loading. It's much better to load everything upfront as
part of boot.
@eregon
Copy link

eregon commented Feb 17, 2022

Which constant(s) are defined when loading a new timezone?
#real_timezone itself looks fine.

@casperisfine
Copy link
Author

If you use the "ruby datasource" it load the individual ruby definition file from tzinfo-data, e.g.: https://github.com/tzinfo/tzinfo-data/blob/324dcf757b014a5ac5f9a44d95b350fa3873a609/lib/tzinfo/data/definitions/Cuba.rb

And they all include TimezoneDefinition which bust the cache a couple more times via append_features:

    module TimezoneDefinition #:nodoc:
      # Adds class methods to the includee.
      #
      # @param base [Module] the includee.
      def self.append_features(base)
        super
        base.extend(Format2::TimezoneDefinition::ClassMethods)
        base.extend(ClassMethods)
      end

philr added a commit that referenced this pull request Jul 17, 2022
An alternative implementation to #129.
@philr
Copy link
Member

philr commented Jul 17, 2022

Thanks for submitting this.

I've implemented something that will achieve the same thing in a slightly different way.

Commit 94be919 adds a preload! method to DataSource. This can be called with TZInfo::DataSource.get.preload!.

The implementation avoids the temporary creation of TimezoneProxy objects for each time zone and also preloads country data for hypothetical data source implementations where this is not loaded up front.

@philr philr closed this Jul 17, 2022
@casperisfine
Copy link
Author

Thanks @philr, it however is infortunate it's not at least aliased as eager_load! as it's the Rails convention that allows to just do:

config.eager_load_namespaces << TZinfo

@philr
Copy link
Member

philr commented Jul 18, 2022

I wasn't aware of that Rails convention.

I've made a further change (c4f177c) to add a TZInfo.eager_load! method in order to support that. The implementation calls the DataSource.

@casperisfine
Copy link
Author

Thank you! That's very helpful.

Copy link

@Skywildlogistics Skywildlogistics left a comment

Choose a reason for hiding this comment

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

Good

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.

None yet

5 participants