⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@stefannibrasil
Copy link
Contributor

@stefannibrasil stefannibrasil commented Jan 15, 2026

Closes #3186

This work has been co-authored with @thdaraujo

The following generators require OpenSSL:

The profiler screenshots show that loading faker spent about 9% of the samples doing that:

vernier run -- ruby -e 'load("/Users/stefannibrasil/projects/faker/lib/faker.rb")'

Call tree:
Profiler Call tree, inverted stack

Stack chart:
Profiler Stack chart

benchmark

CI: took 125.20560900000532ms to load

We tried requiring 'openssl/digest' only but we still needed to require 'openssl' somewhere else.

The next step was testing autoloading OpenSSL.

Autoload OpenSSL

CI: took 80.12221799998542ms to load

require 'benchmark/ips'

Benchmark.ips do |x|
  x.report('autoload openssl') { system('AUTOLOAD=1 ruby load_faker.rb') }
  x.report('require openssl') { system('ruby load_faker.rb') }

  x.compare!(order: :baseline)
end

results

ruby load.rb
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [arm64-darwin24]
Warming up --------------------------------------
     require openssl     1.000 i/100ms
    autoload openssl     1.000 i/100ms
Calculating -------------------------------------
     require openssl     10.485 (± 0.0%) i/s   (95.37 ms/i) -     53.000 in   5.057875s
    autoload openssl     12.429 (± 0.0%) i/s   (80.46 ms/i) -     63.000 in   5.072235s

Comparison:
     require openssl:       10.5 i/s
    autoload openssl:       12.4 i/s - 1.19x  faster

Autoloading OpenSSL is ~19% faster 🚀

Call tree:
Profiler Call tree, inverted stack

Stack Chart:
Profiler Stack Chart

stefannibrasil and others added 3 commits January 15, 2026 12:22
Co-Authored-By: Thiago Araujo <[email protected]>
Profiling laoding faker showed that by autoloading
OpenSSL, we could improve Faker's loading time by about
17%. A lot of the time is spent on set_default_paths.

Given that OpenSSL is only used in a very limited
way and only by 3 generators, this would speed up
the library for most users.

Co-Authored-By: Thiago Araujo <[email protected]>
Copy link
Contributor

@thdaraujo thdaraujo left a comment

Choose a reason for hiding this comment

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

amazing! 🎉

@thdaraujo thdaraujo merged commit 7cc1158 into main Jan 15, 2026
9 checks passed
@thdaraujo thdaraujo deleted the sb-ta/autoload-openssl branch January 15, 2026 21:57
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.

Autoload OpenSSL

3 participants