Load fileutils and etc in persist rather than at require time - #133
Merged
Conversation
tpowell-progress
force-pushed
the
perf/lazy-fileutils-etc
branch
from
August 31, 2026 17:23
91b6e51 to
a4e015d
Compare
tpowell-progress
approved these changes
Aug 31, 2026
tpowell-progress
force-pushed
the
perf/lazy-fileutils-etc
branch
2 times, most recently
from
September 4, 2026 14:01
e697d70 to
64dd296
Compare
strategy/file.rb requires fileutils and etc at the top of the file, but FileUtils.mkdir_p and Etc.getlogin are both reached from persist only, which runs when a license marker file is actually written. Reading acceptance state, the common path, never touches either. Moving both requires into persist takes them off the load path. Interleaved A/B, 20 process launches each, Ruby 4.0.6 on arm64-darwin: require "license_acceptance/strategy/file" before min 16.530 p50 21.238 p90 23.246 ms require "license_acceptance/strategy/file" after min 10.695 p50 12.903 p90 14.685 ms 8.3 ms off the median, about 39%. Both keep their `unless defined?` guards, so they stay no-ops when a consumer has already loaded them, and persist is called once per acceptance rather than in a loop. require "date" is left alone: INVOCATION_TIME is a DateTime built at class definition time, and changing when it is captured would change what gets written into date_accepted. Spec suite passes, 124 examples, 0 failures, including the 8 file_spec examples covering persist. Signed-off-by: Tim Smith <tsmith84@proton.me>
tpowell-progress
force-pushed
the
perf/lazy-fileutils-etc
branch
from
September 4, 2026 15:00
64dd296 to
9fab869
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
components/ruby/lib/license_acceptance/strategy/file.rbrequiresfileutilsandetcat the top of the file, but both are reached frompersistonly:FileUtils.mkdir_p(root_dir)— creating the license directoryEtc.getlogin— stampinguser:into the marker filepersistruns when a license marker file is actually written. Reading acceptance state —accepted?, the common path on every subsequent run — never touches either.Measurements
Interleaved A/B, 20 process launches per arm, Ruby 4.0.6 on arm64-darwin:
require "license_acceptance/strategy/file"beforerequire "license_acceptance/strategy/file"after8.3 ms off the median, about 39%.
Notes
unless defined?guards, so they stay no-ops when a consumer has already loaded them.persistis called once per acceptance, not in a loop, so the in-method require is not on a hot path.require "date"is deliberately left alone:INVOCATION_TIMEis aDateTimebuilt at class-definition time, and making it lazy would change when it is captured and therefore what gets written intodate_accepted.Verification
file_specexamples coveringpersist.require "license_acceptance/strategy/file", neitherFileUtilsnorEtcis defined.This is independent of #132 and the two can land in either order.