SamSaffron/memory_profiler

Comparison of Array with Array failed

Closed this issue · 6 comments

Using this gem via the derailed tool (bundle exec derailed bundle:objects), I receive the following output:

bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/top_n.rb:12:in `sort_by': comparison of Array with Array failed (ArgumentError)
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/top_n.rb:12:in `sort_by!'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/top_n.rb:12:in `top_n' 
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/results.rb:26:in `block in register_results'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/results.rb:24:in `each'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/results.rb:24:in `register_results'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/reporter.rb:63:in `run'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler/reporter.rb:27:in `report'
bundler/gems/memory_profiler-c8255596d985/lib/memory_profiler.rb:14:in `report'
gems/derailed_benchmarks-1.3.1/bin/derailed:51:in `block in <class:DerailedBenchmarkCLI>'

Unfortunately I have no idea what that might mean. Do you think it's a problem of memory_profiler or rather with derailed? Anything I can do to help debug?

dgynn commented

That is probably a problem of memory_profiler. What Ruby and Bundler version are you using? And would it be possible to see your Gemfile?

I'm on Ruby 2.3.1, Bundler version 1.12.5. The Gemfile is unfortunately very large (hence the need to mem-profile it ;)) and contains a number of gems from private repositories so I'm not sure how helpful that might be. But I will try adding a breakpoint to that line and see whether I can narrow down the cause of the problem.

Did some debugging and found that it occurs for the metric :class_name. Once there I did a puts stat_totals and this is the result: https://gist.github.com/milgner/58cac9dc4abc371dc6a8a5285108a4c1

Note the two #<Celluloid::Proxy::Async:*> near the end, I'm guessing those might be the problem.

dgynn commented

Ah, that would be it. That Proxy class inherits from BasicObject and implements method_missing and memory_profiler has been having trouble with that combination. I created a test Gemfile with only derailed_benchmarks and celluloid-io-pg-listener and could recreate the problem.

I have a pending commit that I still want to test some more but it looks like it would fix this. Could you try pointing to my dgynn/memory_profiler repository for the basic_object branch?

Thank you very much for the quick followup! I will gladly give this a try!

Btw, I can confirm that the change from #39 fixed this issue for me.