Skip to content

Generating large JSON (10+ MB) much slower than with Oj #750

@shnikola

Description

@shnikola

We've recently removed Oj from our production app and started using JSON. We are now noticing degraded performance in cases where we need we call to_json on very large objects. Here's a benchmark comparing serializing the attached file with JSON and Oj.

print "Testing JSON...\n"
obj = JSON.parse(File.read("large_example.json"))
objs = [obj] * 10

Benchmark.bm do |x|
  x.report { objs.to_json }
end

Output:

       user     system      total        real
   1.046600   0.061810   1.108410 (  1.107597)
print "Testing OJ...\n"
Oj.optimize_rails
obj = JSON.parse(File.read("large_example.json"))
objs = [obj] * 10

Benchmark.bm do |x|
  x.report { objs.to_json }
end

Output:

       user     system      total        real
   0.103054   0.006695   0.109749 (  0.109749)

large_example.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions