Skip to content

Marshal.load of Hashes slow, especially glacial when vm cold #2085

Open
@LillianZ

Description

@LillianZ

Loading the Hash of Hash of Hash below takes
0.075s on MRI,
0.14s at Truffleruby peak,
... and 3s the first time it is run (21x slower than warm).

This is very unfortunate because in most applications we would only expect to to use Marshal load once at the beginning.

require 'benchmark'
alphabet = "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z".split(", ")
symalphabet = [:AA, :AB, :AC, :AD, :AE, :AF, :AG, :AH, :AI, :AJ, 
 :BA, :BB, :BC, :BD, :BE, :BF, :BG, :BH, :BI, :BJ, 
 :CA, :CB, :CC, :CD, :CE, :CF, :CG, :CH, :CI, :CJ, 
 :DA, :DB, :DC, :DD, :DE, :DF, :DG, :DH, :DI, :DJ, 
 :EA, :EB, :EC, :ED, :EE, :EF, :EG, :EH, :EI, :EJ, 
 :FA, :FB, :FC, :FD, :FE, :FF, :FG, :FH, :FI, :FJ, 
 :GA, :GB, :GC, :GD, :GE, :GF, :GG, :GH, :GI, :GJ, 
 :HA, :HB, :HC, :HD, :HE, :HF, :HG, :HH, :HI, :HJ, 
 :IA, :IB, :IC, :ID, :IE, :IF, :IG, :IH, :II, :IJ, 
 :JA, :JB, :JC, :JD, :JE, :JF, :JG, :JH, :JI, :JJ, 
]
bigh = Hash.new
alphabet.each do |letter1|
  alphabet.each do |letter2|
    h = Hash.new
    symalphabet.each do |symbol|
      h[symbol] = {:a => "String One", :b => "String Two", :c => nil}
    end
    bigh[letter1+letter2] = h
  end
end
str = Marshal.dump(bigh)
puts Benchmark.measure {Marshal.load(str)}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions