ruby-rdf / json-ld

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

fix(performance): comment all log_debug #56

Closed abrisse closed 1 year ago

abrisse commented 1 year ago

Hello @gkellogg,

While investigating some memory issues I discovered that the log_debug calls generate a lot of objects. Half of them were already commented so this PR comments all the others.

I did a small benchmark with memory_profiler:

allocated memory by gem (current)
-------------------------------------------------------
  48.30 MB  json-ld
  41.03 MB  rdf-ac80b2f2b82e

allocated memory by gem (with all log_debug commented)
-------------------------------------------------------
  43.33 MB  json-ld (- 10%)
  15.79 MB  rdf-ac80b2f2b82e (- 42%)

The 3 lines that stores a lot of objects:

This is partly because the RDF utils functions logger_debug / logger_common use splat operators which is quite costly, so I think the PR provide the best ROI.

coveralls commented 1 year ago

Coverage Status

Coverage: 84.444% (-1.0%) from 85.432% when pulling 18f84e81485750dc52082ba0e3155440ebc29254 on PerfectMemory:fix/debug-log into 742eecbf47237833071b8bf2dc18a258271923bf on ruby-rdf:develop.

gkellogg commented 1 year ago

Interesting and unfortunate. I've tried to decrease the impact of log_* calls by leaving costly evaluation in the block, but there's no good way to avoid splat arguments. I've gone back and forth about commenting out logging, and it can be useful when trying to debug gnarly corner-cases. But, the log_debug calls probably make up the bulk and shouldn't be as necessary to get basic algorithm tracing as log_info, for example.