ruby-rdf / json-ld

Ruby JSON-LD reader/writer for RDF.rb
The Unlicense
232 stars 27 forks source link

Performance fixes #41

Closed jperville closed 7 years ago

jperville commented 7 years ago

Summary

This PR contains all the improvements I made from profiling the JSON::LD::API#frame method.

If all commits from this PR and sister PR https://github.com/ruby-rdf/rdf/pull/360 are applied, the number of objects allocated in my sample scenario drops around 32% and the runtime is improved by 20% (on Ruby 2.4, which is recommended because of the frozen string literal feature).

I would appreciate if you can do some code review before accepting the PR @gkellogg .

The details

I did not have the chance to run the whole json-ld test suite (broken since #40) but at least for each commit I verified that the CI=true bundle exec rake spec command passes, and that there is no regression in the ntriple representation of the graph that I have been framing.

This PR was developed using a sample scenario (ntriples graph that we want to frame to a certain context). The scenario was run multiple times (here 10) and I kept track of ruby object allocations using stackprof.

The sample scenario run 10 times would allocate 906000 objects at the start, and at the end only 623000, a reduction of around 32% of allocated objects. The run time was cut by around 20% (on ruby 2.4).

Here was my progression in reducing the allocated object count (each step should have a corresponding commit in this PR):

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.1%) to 89.07% when pulling 178afc2c014d69db75bd9447ed3cb166f98ee055 on PerfectMemory:performance-fixes into a1a01db875afbb8759b0cac10b7d1aa73034a3d8 on ruby-rdf:develop.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.1%) to 89.07% when pulling 178afc2c014d69db75bd9447ed3cb166f98ee055 on PerfectMemory:performance-fixes into a1a01db875afbb8759b0cac10b7d1aa73034a3d8 on ruby-rdf:develop.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.1%) to 89.07% when pulling 178afc2c014d69db75bd9447ed3cb166f98ee055 on PerfectMemory:performance-fixes into a1a01db875afbb8759b0cac10b7d1aa73034a3d8 on ruby-rdf:develop.

jperville commented 7 years ago

Hello @gkellogg , could you cut a new release of json-ld gem? Thank you very much.

gkellogg commented 7 years ago

Released as 2.1.6.