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

Speedup require and first call #2719

Open
stoivo opened this issue Feb 23, 2023 · 3 comments
Open

Speedup require and first call #2719

stoivo opened this issue Feb 23, 2023 · 3 comments

Comments

@stoivo
Copy link

stoivo commented Feb 23, 2023

Hi, I use faker and I noticed that some parts are slower then what I would have liked. I wonder if you have had some ideas for what you would like to do to make it faster to load and use.

I did a bit of testing locally. I an running on a bit older mac(MacBood Pro 2014). Below you can see how I tested some parts.

Most of the time is spent the first time we call Faker::Coin.flip 1332ms, I confident this is because we have many different yaml files which are loaded into I18n. I havn't tested but maybe it is faster if it one file instead of several?

The first think I tested what if I require less files then you require faker. I think we can save 30% (100ms in my case) of require time by using zeitwerk to load all the different extra files. Would you accept a merge requies switching to zeitwerk?

Script

t = Time.now.to_f * 1000
require_relative "lib/faker"
tt = Time.now.to_f * 1000
puts "Time: #{tt - t}ms Time of require faker"

10.times do
  t = Time.now.to_f * 1000
  fake = Faker::Coin.flip
  tt = Time.now.to_f * 1000
  puts "Time: #{tt - t}ms Faker::Coin.flip (#{fake})"
end

before:
Time: 214.383056640625ms Time of require faker
Time: 1423.72900390625ms Faker::Coin.flip (Heads)
Time: 0.072998046875ms Faker::Coin.flip (Tails)
Time: 0.08984375ms Faker::Coin.flip (Heads)
Time: 0.281005859375ms Faker::Coin.flip (Heads)
Time: 0.237060546875ms Faker::Coin.flip (Heads)
Time: 2.384765625ms Faker::Coin.flip (Heads)
Time: 0.08203125ms Faker::Coin.flip (Heads)
Time: 0.07177734375ms Faker::Coin.flip (Heads)
Time: 0.083984375ms Faker::Coin.flip (Tails)
Time: 0.066162109375ms Faker::Coin.flip (Heads)

replaced
Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).sort.each { |file| require file }

with
require "/Users/simon/Downloads/faker/lib/faker/default/coin.rb"
require "/Users/simon/Downloads/faker/lib/faker/version.rb"

after:
Time: 310.723876953125ms Time of require faker
Time: 1332.678466796875ms Faker::Coin.flip (Tails)
Time: 0.044189453125ms Faker::Coin.flip (Heads)
Time: 0.08154296875ms Faker::Coin.flip (Heads)
Time: 0.064208984375ms Faker::Coin.flip (Heads)
Time: 0.06005859375ms Faker::Coin.flip (Tails)
Time: 0.100830078125ms Faker::Coin.flip (Tails)
Time: 0.09375ms Faker::Coin.flip (Tails)
Time: 0.075927734375ms Faker::Coin.flip (Tails)
Time: 0.066162109375ms Faker::Coin.flip (Heads)
Time: 0.06982421875ms Faker::Coin.flip (Heads)

@stoivo
Copy link
Author

stoivo commented Feb 24, 2023

I looked into why is spends 1400ms to get the first. It is because it takes so so much time parse yaml

I created this script to check.

# frozen_string_literal: true

def it_takes(string)
  t = Time.now.to_f * 1000
  r = yield
  tt = Time.now.to_f * 1000
  print "#{('%.4f' % (tt - t) ).to_s.rjust(20)}ms Done with #{string}\n"
  r
end

it_takes "require psych" do
  require 'psych'
  require 'yaml'
end

Dir[File.join(__dir__, 'locales', '**/*.yml')]
  .each do |file|
    it_takes "file #{file} " do
      YAML.unsafe_load_file(file, symbolize_names: true, freeze: true)
    end
  end

it_takes "all " do
  Dir[File.join(__dir__, 'locales', '**/*.yml')]
    .each do |file|
      YAML.unsafe_load_file(file, symbolize_names: true, freeze: true)
    end
end
results
             32.7817ms Done with require psych
                (ordered them to is easyer to see which are slower)
              0.1248ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/demographic.yml
              0.1460ms Done with file /Users/simon/Downloads/faker/lib/locales/en/markdown.yml
              0.1660ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/internet.yml
              0.1750ms Done with file /Users/simon/Downloads/faker/lib/locales/en/gender.yml
              0.1770ms Done with file /Users/simon/Downloads/faker/lib/locales/en/mountaineering.yml
              0.1851ms Done with file /Users/simon/Downloads/faker/lib/locales/en/business.yml
              0.2104ms Done with file /Users/simon/Downloads/faker/lib/locales/fr.yml
              0.2109ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/measurement.yml
              0.2219ms Done with file /Users/simon/Downloads/faker/lib/locales/en/coin.yml
              0.2271ms Done with file /Users/simon/Downloads/faker/lib/locales/en/final_space.yml
              0.2273ms Done with file /Users/simon/Downloads/faker/lib/locales/en/invoice.yml
              0.2402ms Done with file /Users/simon/Downloads/faker/lib/locales/en/measurement.yml
              0.2449ms Done with file /Users/simon/Downloads/faker/lib/locales/en/barcode.yml
              0.2471ms Done with file /Users/simon/Downloads/faker/lib/locales/en/crypto_coin.yml
              0.2551ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/phone_number.yml
              0.2559ms Done with file /Users/simon/Downloads/faker/lib/locales/en/brooklyn_nine_nine.yml
              0.2568ms Done with file /Users/simon/Downloads/faker/lib/locales/en/greek_philosophers.yml
              0.2578ms Done with file /Users/simon/Downloads/faker/lib/locales/en/marketing.yml
              0.2588ms Done with file /Users/simon/Downloads/faker/lib/locales/en/blood.yml
              0.2681ms Done with file /Users/simon/Downloads/faker/lib/locales/en/electrical_components.yml
              0.2798ms Done with file /Users/simon/Downloads/faker/lib/locales/en/michael_scott.yml
              0.2842ms Done with file /Users/simon/Downloads/faker/lib/locales/en/esport.yml
              0.2888ms Done with file /Users/simon/Downloads/faker/lib/locales/en/family_guy.yml
              0.2959ms Done with file /Users/simon/Downloads/faker/lib/locales/en/big_bang_theory.yml
              0.3098ms Done with file /Users/simon/Downloads/faker/lib/locales/en.yml
              0.3171ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hackers.yml
              0.3210ms Done with file /Users/simon/Downloads/faker/lib/locales/en/rush.yml
              0.3218ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dessert.yml
              0.3320ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/zelda.yml
              0.3379ms Done with file /Users/simon/Downloads/faker/lib/locales/en/id_number.yml
              0.3408ms Done with file /Users/simon/Downloads/faker/lib/locales/en/computer.yml
              0.3433ms Done with file /Users/simon/Downloads/faker/lib/locales/en/suits.yml
              0.3491ms Done with file /Users/simon/Downloads/faker/lib/locales/en/nato_phonetic_alphabet.yml
              0.3582ms Done with file /Users/simon/Downloads/faker/lib/locales/en/source.yml
              0.3601ms Done with file /Users/simon/Downloads/faker/lib/locales/en/lovecraft.yml
              0.3650ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/compass.yml
              0.3772ms Done with file /Users/simon/Downloads/faker/lib/locales/en/community.yml
              0.3801ms Done with file /Users/simon/Downloads/faker/lib/locales/en/aqua_teen_hunger_force.yml
              0.3840ms Done with file /Users/simon/Downloads/faker/lib/locales/no.yml
              0.3972ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/book.yml
              0.4006ms Done with file /Users/simon/Downloads/faker/lib/locales/en/house.yml
              0.4048ms Done with file /Users/simon/Downloads/faker/lib/locales/en/departed.yml
              0.4048ms Done with file /Users/simon/Downloads/faker/lib/locales/en/super_mario.yml
              0.4053ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/space.yml
              0.4060ms Done with file /Users/simon/Downloads/faker/lib/locales/en/bojack_horseman.yml
              0.4060ms Done with file /Users/simon/Downloads/faker/lib/locales/en/subscription.yml
              0.4080ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/appliance.yml
              0.4109ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/phone_number.yml
              0.4116ms Done with file /Users/simon/Downloads/faker/lib/locales/en/grateful_dead.yml
              0.4148ms Done with file /Users/simon/Downloads/faker/lib/locales/en/artist.yml
              0.4158ms Done with file /Users/simon/Downloads/faker/lib/locales/en/file.yml
              0.4170ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/overwatch.yml
              0.4182ms Done with file /Users/simon/Downloads/faker/lib/locales/en/south_park.yml
              0.4199ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/gender.yml
              0.4280ms Done with file /Users/simon/Downloads/faker/lib/locales/en/relationship.yml
              0.4351ms Done with file /Users/simon/Downloads/faker/lib/locales/en/breaking_bad.yml
              0.4438ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/university.yml
              0.4441ms Done with file /Users/simon/Downloads/faker/lib/locales/en/bossa_nova.yml
              0.4458ms Done with file /Users/simon/Downloads/faker/lib/locales/en/educator.yml
              0.4492ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dumb_and_dumber.yml
              0.4492ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hacker.yml
              0.4502ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/gender.yml
              0.4521ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/animal.yml
              0.4609ms Done with file /Users/simon/Downloads/faker/lib/locales/en/room.yml
              0.4622ms Done with file /Users/simon/Downloads/faker/lib/locales/en/color.yml
              0.4631ms Done with file /Users/simon/Downloads/faker/lib/locales/en/device.yml
              0.4670ms Done with file /Users/simon/Downloads/faker/lib/locales/en/chess.yml
              0.4707ms Done with file /Users/simon/Downloads/faker/lib/locales/en/basketball.yml
              0.4709ms Done with file /Users/simon/Downloads/faker/lib/locales/en/jack_handey.yml
              0.4797ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/super_smash_bros.yml
              0.4849ms Done with file /Users/simon/Downloads/faker/lib/locales/en/shakespeare.yml
              0.4907ms Done with file /Users/simon/Downloads/faker/lib/locales/en/yoda.yml
              0.4978ms Done with file /Users/simon/Downloads/faker/lib/locales/en/drone.yml
              0.5022ms Done with file /Users/simon/Downloads/faker/lib/locales/en/appliance.yml
              0.5146ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/ancient.yml
              0.5242ms Done with file /Users/simon/Downloads/faker/lib/locales/en/half_life.yml
              0.5391ms Done with file /Users/simon/Downloads/faker/lib/locales/en/ghostbusters.yml
              0.5400ms Done with file /Users/simon/Downloads/faker/lib/locales/en/lebowski.yml
              0.5420ms Done with file /Users/simon/Downloads/faker/lib/locales/en/cat.yml
              0.5449ms Done with file /Users/simon/Downloads/faker/lib/locales/en/how_i_met_your_mother.yml
              0.5569ms Done with file /Users/simon/Downloads/faker/lib/locales/en/new_girl.yml
              0.5691ms Done with file /Users/simon/Downloads/faker/lib/locales/en/bible.yml
              0.5720ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/relationship.yml
              0.5750ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dc_comics.yml
              0.5791ms Done with file /Users/simon/Downloads/faker/lib/locales/en/the_expanse.yml
              0.5808ms Done with file /Users/simon/Downloads/faker/lib/locales/en/compass.yml
              0.5901ms Done with file /Users/simon/Downloads/faker/lib/locales/en/rajnikanth.yml
              0.6233ms Done with file /Users/simon/Downloads/faker/lib/locales/en/stripe.yml
              0.6262ms Done with file /Users/simon/Downloads/faker/lib/locales/en/app.yml
              0.6282ms Done with file /Users/simon/Downloads/faker/lib/locales/en/team.yml
              0.6589ms Done with file /Users/simon/Downloads/faker/lib/locales/en/world_of_warcraft.yml
              0.6687ms Done with file /Users/simon/Downloads/faker/lib/locales/tr.yml
              0.6792ms Done with file /Users/simon/Downloads/faker/lib/locales/en/commerce.yml
              0.6892ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/ancient.yml
              0.6931ms Done with file /Users/simon/Downloads/faker/lib/locales/en/job.yml
              0.6980ms Done with file /Users/simon/Downloads/faker/lib/locales/en/rupaul.yml
              0.7009ms Done with file /Users/simon/Downloads/faker/lib/locales/en/stranger_thing.yml
              0.7058ms Done with file /Users/simon/Downloads/faker/lib/locales/en/seinfeld.yml
              0.7170ms Done with file /Users/simon/Downloads/faker/lib/locales/en/star_trek.yml
              0.7219ms Done with file /Users/simon/Downloads/faker/lib/locales/en/australia.yml
              0.7339ms Done with file /Users/simon/Downloads/faker/lib/locales/en/mountain.yml
              0.7439ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/color.yml
              0.7471ms Done with file /Users/simon/Downloads/faker/lib/locales/en/animal.yml
              0.7490ms Done with file /Users/simon/Downloads/faker/lib/locales/en/demographic.yml
              0.7568ms Done with file /Users/simon/Downloads/faker/lib/locales/en/industry_segments.yml
              0.7622ms Done with file /Users/simon/Downloads/faker/lib/locales/en/football.yml
              0.7700ms Done with file /Users/simon/Downloads/faker/lib/locales/en/conan.yml
              0.7910ms Done with file /Users/simon/Downloads/faker/lib/locales/en/parks_and_rec.yml
              0.8320ms Done with file /Users/simon/Downloads/faker/lib/locales/en/adjective.yml
              0.8330ms Done with file /Users/simon/Downloads/faker/lib/locales/en/friends.yml
              0.8340ms Done with file /Users/simon/Downloads/faker/lib/locales/en/cosmere.yml
              0.8350ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/restaurant.yml
              0.8379ms Done with file /Users/simon/Downloads/faker/lib/locales/en/princess_bride.yml
              0.8467ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/subscription.yml
              0.8491ms Done with file /Users/simon/Downloads/faker/lib/locales/en/restaurant.yml
              0.8518ms Done with file /Users/simon/Downloads/faker/lib/locales/en/supernatural.yml
              0.8530ms Done with file /Users/simon/Downloads/faker/lib/locales/en/internet.yml
              0.8723ms Done with file /Users/simon/Downloads/faker/lib/locales/en/rick_and_morty.yml
              0.8730ms Done with file /Users/simon/Downloads/faker/lib/locales/en/how_to_train_your_dragon.yml
              0.8740ms Done with file /Users/simon/Downloads/faker/lib/locales/en/control.yml
              0.8796ms Done with file /Users/simon/Downloads/faker/lib/locales/en/university.yml
              0.9031ms Done with file /Users/simon/Downloads/faker/lib/locales/en/clash_of_clan.yml
              0.9031ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dragon_ball.yml
              0.9258ms Done with file /Users/simon/Downloads/faker/lib/locales/en/naruto.yml
              0.9302ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hey_arnold.yml
              0.9326ms Done with file /Users/simon/Downloads/faker/lib/locales/en/avatar.yml
              0.9338ms Done with file /Users/simon/Downloads/faker/lib/locales/en/rock_band.yml
              0.9741ms Done with file /Users/simon/Downloads/faker/lib/locales/en/back_to_the_future.yml
              0.9778ms Done with file /Users/simon/Downloads/faker/lib/locales/en/driving_license.yml
              0.9910ms Done with file /Users/simon/Downloads/faker/lib/locales/en/the_office.yml
              1.0007ms Done with file /Users/simon/Downloads/faker/lib/locales/en/harry_potter.yml
              1.0168ms Done with file /Users/simon/Downloads/faker/lib/locales/en/super_smash_bros.yml
              1.0229ms Done with file /Users/simon/Downloads/faker/lib/locales/en/league_of_legends.yml
              1.0342ms Done with file /Users/simon/Downloads/faker/lib/locales/en/cannabis.yml
              1.0361ms Done with file /Users/simon/Downloads/faker/lib/locales/en-BORK.yml
              1.0449ms Done with file /Users/simon/Downloads/faker/lib/locales/en/the_thick_of_it.yml
              1.0481ms Done with file /Users/simon/Downloads/faker/lib/locales/en/sport.yml
              1.0552ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/adjective.yml
              1.0601ms Done with file /Users/simon/Downloads/faker/lib/locales/en/myst.yml
              1.0940ms Done with file /Users/simon/Downloads/faker/lib/locales/en/buffy.yml
              1.0986ms Done with file /Users/simon/Downloads/faker/lib/locales/en/game.yml
              1.1028ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hipster.yml
              1.1069ms Done with file /Users/simon/Downloads/faker/lib/locales/en/culture_series.yml
              1.1140ms Done with file /Users/simon/Downloads/faker/lib/locales/en/chuck_norris.yml
              1.1182ms Done with file /Users/simon/Downloads/faker/lib/locales/en/fresh_prince_of_bel_air.yml
              1.1238ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/super_mario.yml
              1.1243ms Done with file /Users/simon/Downloads/faker/lib/locales/en/the_kingkiller_chronicle.yml
              1.1440ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/coffee.yml
              1.1528ms Done with file /Users/simon/Downloads/faker/lib/locales/en/movie.yml
              1.1531ms Done with file /Users/simon/Downloads/faker/lib/locales/en/beer.yml
              1.1753ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/pokemon.yml
              1.1760ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hobby.yml
              1.2019ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dog.yml
              1.2019ms Done with file /Users/simon/Downloads/faker/lib/locales/en/fallout.yml
              1.2051ms Done with file /Users/simon/Downloads/faker/lib/locales/en/currency.yml
              1.2109ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/company.yml
              1.2222ms Done with file /Users/simon/Downloads/faker/lib/locales/en/doraemon.yml
              1.2341ms Done with file /Users/simon/Downloads/faker/lib/locales/en/chiquito.yml
              1.2429ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/emotion.yml
              1.2810ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/cat.yml
              1.2898ms Done with file /Users/simon/Downloads/faker/lib/locales/en/futurama.yml
              1.2954ms Done with file /Users/simon/Downloads/faker/lib/locales/en/tea.yml
              1.2981ms Done with file /Users/simon/Downloads/faker/lib/locales/he.yml
              1.3091ms Done with file /Users/simon/Downloads/faker/lib/locales/en/silicon_valley.yml
              1.3320ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/name.yml
              1.3608ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/studio_ghibli.yml
              1.3711ms Done with file /Users/simon/Downloads/faker/lib/locales/en/the_it_crowd.yml
              1.3779ms Done with file /Users/simon/Downloads/faker/lib/locales/mi-NZ.yml
              1.3787ms Done with file /Users/simon/Downloads/faker/lib/locales/en/horse.yml
              1.3850ms Done with file /Users/simon/Downloads/faker/lib/locales/en/construction.yml
              1.3989ms Done with file /Users/simon/Downloads/faker/lib/locales/en/cowboy_bebop.yml
              1.4182ms Done with file /Users/simon/Downloads/faker/lib/locales/en/ancient.yml
              1.4277ms Done with file /Users/simon/Downloads/faker/lib/locales/en/twin_peaks.yml
              1.4590ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/color.yml
              1.4780ms Done with file /Users/simon/Downloads/faker/lib/locales/en/phone_number.yml
              1.4819ms Done with file /Users/simon/Downloads/faker/lib/locales/en/fma_brotherhood.yml
              1.4851ms Done with file /Users/simon/Downloads/faker/lib/locales/en/venture_bros.yml
              1.5132ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/naruto.yml
              1.5190ms Done with file /Users/simon/Downloads/faker/lib/locales/ca-CAT.yml
              1.5342ms Done with file /Users/simon/Downloads/faker/lib/locales/en/emotion.yml
              1.5789ms Done with file /Users/simon/Downloads/faker/lib/locales/en/studio_ghibli.yml
              1.6350ms Done with file /Users/simon/Downloads/faker/lib/locales/en/heroes_of_the_storm.yml
              1.6392ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/commerce.yml
              1.6514ms Done with file /Users/simon/Downloads/faker/lib/locales/en/sword_art_online.yml
              1.6606ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/company.yml
              1.6677ms Done with file /Users/simon/Downloads/faker/lib/locales/en/umphreys_mcgee.yml
              1.6711ms Done with file /Users/simon/Downloads/faker/lib/locales/en/pearl_jam.yml
              1.6719ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/animal.yml
              1.6770ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dr_who.yml
              1.6912ms Done with file /Users/simon/Downloads/faker/lib/locales/th.yml
              1.7080ms Done with file /Users/simon/Downloads/faker/lib/locales/en-NEP.yml
              1.7700ms Done with file /Users/simon/Downloads/faker/lib/locales/en/stargate.yml
              1.8088ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dune.yml
              1.8140ms Done with file /Users/simon/Downloads/faker/lib/locales/en/tron.yml
              1.8203ms Done with file /Users/simon/Downloads/faker/lib/locales/en/airport.yml
              1.8750ms Done with file /Users/simon/Downloads/faker/lib/locales/en/superhero.yml
              1.8938ms Done with file /Users/simon/Downloads/faker/lib/locales/en-GB.yml
              1.9412ms Done with file /Users/simon/Downloads/faker/lib/locales/en/code.yml
              1.9797ms Done with file /Users/simon/Downloads/faker/lib/locales/en/heroes.yml
              1.9819ms Done with file /Users/simon/Downloads/faker/lib/locales/nb-NO.yml
              2.0210ms Done with file /Users/simon/Downloads/faker/lib/locales/en/book.yml
              2.0752ms Done with file /Users/simon/Downloads/faker/lib/locales/en/bank.yml
              2.0781ms Done with file /Users/simon/Downloads/faker/lib/locales/ca.yml
              2.0959ms Done with file /Users/simon/Downloads/faker/lib/locales/en/camera.yml
              2.1809ms Done with file /Users/simon/Downloads/faker/lib/locales/en/science.yml
              2.2180ms Done with file /Users/simon/Downloads/faker/lib/locales/vi.yml
              2.2729ms Done with file /Users/simon/Downloads/faker/lib/locales/en-au-ocker.yml
              2.2820ms Done with file /Users/simon/Downloads/faker/lib/locales/en/space.yml
              2.3816ms Done with file /Users/simon/Downloads/faker/lib/locales/en/hitchhikers_guide_to_the_galaxy.yml
              2.4170ms Done with file /Users/simon/Downloads/faker/lib/locales/da-DK.yml
              2.4819ms Done with file /Users/simon/Downloads/faker/lib/locales/en/military.yml
              2.4839ms Done with file /Users/simon/Downloads/faker/lib/locales/en/kpop.yml
              2.5181ms Done with file /Users/simon/Downloads/faker/lib/locales/en/one_piece.yml
              2.5439ms Done with file /Users/simon/Downloads/faker/lib/locales/en/elder_scrolls.yml
              2.5713ms Done with file /Users/simon/Downloads/faker/lib/locales/en/kamen_rider.yml
              2.5840ms Done with file /Users/simon/Downloads/faker/lib/locales/en/funny_name.yml
              2.6560ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/pokemon.yml
              2.6770ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/bank.yml
              2.7310ms Done with file /Users/simon/Downloads/faker/lib/locales/en/sonic_the_hedgehog.yml
              2.8049ms Done with file /Users/simon/Downloads/faker/lib/locales/en/coffee.yml
              2.8406ms Done with file /Users/simon/Downloads/faker/lib/locales/en/show.yml
              2.8550ms Done with file /Users/simon/Downloads/faker/lib/locales/zh-CN.yml
              2.8669ms Done with file /Users/simon/Downloads/faker/lib/locales/en/prince.yml
              2.9548ms Done with file /Users/simon/Downloads/faker/lib/locales/en/opera.yml
              3.1428ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/food.yml
              3.1609ms Done with file /Users/simon/Downloads/faker/lib/locales/lt.yml
              3.2158ms Done with file /Users/simon/Downloads/faker/lib/locales/en-MS.yml
              3.2717ms Done with file /Users/simon/Downloads/faker/lib/locales/en/tarkov.yml
              3.2913ms Done with file /Users/simon/Downloads/faker/lib/locales/en/lorem.yml
              3.3040ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/adjective.yml
              3.3108ms Done with file /Users/simon/Downloads/faker/lib/locales/en/finance.yml
              3.4077ms Done with file /Users/simon/Downloads/faker/lib/locales/fi-FI.yml
              3.4082ms Done with file /Users/simon/Downloads/faker/lib/locales/en/zelda.yml
              3.4634ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/address.yml
              3.4751ms Done with file /Users/simon/Downloads/faker/lib/locales/en/pokemon.yml
              3.5181ms Done with file /Users/simon/Downloads/faker/lib/locales/en-NG.yml
              3.5791ms Done with file /Users/simon/Downloads/faker/lib/locales/ee.yml
              3.6941ms Done with file /Users/simon/Downloads/faker/lib/locales/en/witcher.yml
              3.7119ms Done with file /Users/simon/Downloads/faker/lib/locales/en/phish.yml
              3.7249ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/lorem.yml
              3.7310ms Done with file /Users/simon/Downloads/faker/lib/locales/ko.yml
              3.8032ms Done with file /Users/simon/Downloads/faker/lib/locales/en-TH.yml
              3.8640ms Done with file /Users/simon/Downloads/faker/lib/locales/en/v_for_vendetta.yml
              3.8643ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/book.yml
              3.8718ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dota.yml
              3.9204ms Done with file /Users/simon/Downloads/faker/lib/locales/en-UG.yml
              4.0288ms Done with file /Users/simon/Downloads/faker/lib/locales/en/spongebob.yml
              4.0320ms Done with file /Users/simon/Downloads/faker/lib/locales/id.yml
              4.1709ms Done with file /Users/simon/Downloads/faker/lib/locales/fr/name.yml
              4.3193ms Done with file /Users/simon/Downloads/faker/lib/locales/it.yml
              4.4949ms Done with file /Users/simon/Downloads/faker/lib/locales/pt.yml
              4.6001ms Done with file /Users/simon/Downloads/faker/lib/locales/en/programming_language.yml
              4.8391ms Done with file /Users/simon/Downloads/faker/lib/locales/sv.yml
              4.8850ms Done with file /Users/simon/Downloads/faker/lib/locales/en/bird.yml
              4.9160ms Done with file /Users/simon/Downloads/faker/lib/locales/bg.yml
              4.9392ms Done with file /Users/simon/Downloads/faker/lib/locales/en/minecraft.yml
              4.9612ms Done with file /Users/simon/Downloads/faker/lib/locales/en/food.yml
              5.1108ms Done with file /Users/simon/Downloads/faker/lib/locales/en-CA.yml
              5.2258ms Done with file /Users/simon/Downloads/faker/lib/locales/en/star_wars.yml
              5.2439ms Done with file /Users/simon/Downloads/faker/lib/locales/en/company.yml
              5.3320ms Done with file /Users/simon/Downloads/faker/lib/locales/en/warhammer_fantasy.yml
              5.5000ms Done with file /Users/simon/Downloads/faker/lib/locales/en/dnd.yml
              5.6538ms Done with file /Users/simon/Downloads/faker/lib/locales/en/quote.yml
              5.7559ms Done with file /Users/simon/Downloads/faker/lib/locales/en/touhou.yml
              5.8633ms Done with file /Users/simon/Downloads/faker/lib/locales/en/slack_emoji.yml
              6.0200ms Done with file /Users/simon/Downloads/faker/lib/locales/en-SG.yml
              6.1099ms Done with file /Users/simon/Downloads/faker/lib/locales/en-PAK.yml
              6.1907ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/dog.yml
              6.4341ms Done with file /Users/simon/Downloads/faker/lib/locales/ar.yml
              6.4800ms Done with file /Users/simon/Downloads/faker/lib/locales/en/music.yml
              6.5042ms Done with file /Users/simon/Downloads/faker/lib/locales/lv.yml
              6.7393ms Done with file /Users/simon/Downloads/faker/lib/locales/en/game_of_thrones.yml
              6.8171ms Done with file /Users/simon/Downloads/faker/lib/locales/en-AU.yml
              6.8203ms Done with file /Users/simon/Downloads/faker/lib/locales/en/volleyball.yml
              7.1501ms Done with file /Users/simon/Downloads/faker/lib/locales/de-CH.yml
              7.1550ms Done with file /Users/simon/Downloads/faker/lib/locales/zh-TW.yml
              7.9329ms Done with file /Users/simon/Downloads/faker/lib/locales/en-NZ.yml
              8.8530ms Done with file /Users/simon/Downloads/faker/lib/locales/en/address.yml
              8.8801ms Done with file /Users/simon/Downloads/faker/lib/locales/en-ZA.yml
              8.9929ms Done with file /Users/simon/Downloads/faker/lib/locales/en-IND.yml
              9.2961ms Done with file /Users/simon/Downloads/faker/lib/locales/en/simpsons.yml
             10.1011ms Done with file /Users/simon/Downloads/faker/lib/locales/en/world_cup.yml
             10.2058ms Done with file /Users/simon/Downloads/faker/lib/locales/fr-CH.yml
             10.7178ms Done with file /Users/simon/Downloads/faker/lib/locales/en/street_fighter.yml
             10.8052ms Done with file /Users/simon/Downloads/faker/lib/locales/fa.yml
             11.2529ms Done with file /Users/simon/Downloads/faker/lib/locales/es.yml
             11.2949ms Done with file /Users/simon/Downloads/faker/lib/locales/ru.yml
             12.2878ms Done with file /Users/simon/Downloads/faker/lib/locales/es-MX.yml
             13.3691ms Done with file /Users/simon/Downloads/faker/lib/locales/uk.yml
             16.7761ms Done with file /Users/simon/Downloads/faker/lib/locales/en/overwatch.yml
             16.8738ms Done with file /Users/simon/Downloads/faker/lib/locales/fr-CA.yml
             17.6042ms Done with file /Users/simon/Downloads/faker/lib/locales/en/nation.yml
             17.6389ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/lorem.yml
             18.0691ms Done with file /Users/simon/Downloads/faker/lib/locales/de-AT.yml
             19.8259ms Done with file /Users/simon/Downloads/faker/lib/locales/en/vehicle.yml
             20.5188ms Done with file /Users/simon/Downloads/faker/lib/locales/pl.yml
             23.4182ms Done with file /Users/simon/Downloads/faker/lib/locales/hy.yml
             24.3218ms Done with file /Users/simon/Downloads/faker/lib/locales/en/tolkien.yml
             26.1982ms Done with file /Users/simon/Downloads/faker/lib/locales/es-AR.yml
             27.6831ms Done with file /Users/simon/Downloads/faker/lib/locales/en/verbs.yml
             30.7529ms Done with file /Users/simon/Downloads/faker/lib/locales/sk.yml
             31.3342ms Done with file /Users/simon/Downloads/faker/lib/locales/de.yml
             35.5652ms Done with file /Users/simon/Downloads/faker/lib/locales/en/name.yml
             40.3799ms Done with file /Users/simon/Downloads/faker/lib/locales/pt-BR.yml
             45.0242ms Done with file /Users/simon/Downloads/faker/lib/locales/en-US.yml
            134.9246ms Done with file /Users/simon/Downloads/faker/lib/locales/nl.yml
            502.4958ms Done with file /Users/simon/Downloads/faker/lib/locales/ja/address.yml
           1403.1340ms Time it take to parse each yaml file

Knowing this I'm not sure it is worth spending any time speeding up require by 100ms(of a total of 300ms) if we will spend 1400ms parsing yaml. The only way I see this becoming faster is to remove i18n and lazy load those yaml files we need. For that, to work we need to restructure the yaml files so we know whay they contain without parsing it

I can spend some time working on this, but I want to know if it is a chance that it will be merged, and how you would like to have it.

@stoivo
Copy link
Author

stoivo commented Feb 24, 2023

You could also argue that it is better not to pollute I18n with fakers translations

@Alireza17224
Copy link

Alireza17224 commented Sep 3, 2023

Same issue here.
Too slow
[Done] exited with code=0 in 0.852 seconds

require "faker"

p Faker::ProgrammingLanguage.name #=> "Ruby"

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

No branches or pull requests

2 participants