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

Remove $LOAD_PATH modifications #269

Merged
merged 2 commits into from
Aug 27, 2022
Merged

Conversation

daniel-rikowski
Copy link
Contributor

I was investigating the slow startup performance of a Rails application using Bumbler (https://github.com/nevir/Bumbler)

I was quite surprised to always see ruby-units in place 1 or 2 as the worst offender, adding about 1 second to the total startup time.

After some investigation I noticed that this comes from an unfortunate interaction with the bootsnap gem (bootsnap improves the startup time of an app by caching and pre-scanning the load path, see https://github.com/Shopify/bootsnap#path-pre-scanning)

By modifying $LOAD_PATH twice, bootsnap requires rescans the whole load path twice by adding the current directory to the load path. The duration depends on the number of installed gems. In my case this is adding a considerable delay to the application startup.

$LOAD_PATH << File.dirname(__FILE__)
require_relative 'ruby_units/namespaced'

$LOAD_PATH << File.dirname(__FILE__)
# require_relative this file to avoid creating an class alias from Unit to RubyUnits::Unit
require_relative 'version'

Fortunately these modifications are not necessary, because require_relative is used which already considers the current directory.

My guess: previously require was used and the load path modifications were actually necessary. After switching to require_relative they became useless but weren't removed.

Anyway, this PR removes them.

They are not needed, but still are invalidating any Bootsnap load path cache if present.
@olbrich
Copy link
Owner

olbrich commented Aug 22, 2022

@daniel-rikowski Thanks for catching that!

@olbrich olbrich added bug Patch backwards-compatible bug fixes labels Aug 22, 2022
@olbrich olbrich self-assigned this Aug 22, 2022
@olbrich olbrich merged commit 3120be3 into olbrich:master Aug 27, 2022
@olbrich olbrich added this to the v2.4.1 milestone Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants