Skip to content

Conversation

chrisseaton
Copy link
Collaborator

We get failures while tracing allocations from C extensions. I think this fixes it, but I'm not keen to try to architect a test case, to be honest.

@chrisseaton chrisseaton self-assigned this Jul 15, 2021
@chrisseaton chrisseaton added shopify Pull requests from Shopify bug labels Jul 15, 2021
@eregon
Copy link
Member

eregon commented Jul 15, 2021

In general I feel ObjectSpace.trace_object_allocations is crazily expensive, and something we should probably give a performance warning for.
CRuby docs also say:

Note that this feature introduces a huge performance decrease and huge
memory consumption.

So I think of it as something that should only be used for debugging.
Also notes it invalidates a lot of code when enabling/disabling allocation tracing.

One thing we could do to make it a little bit less horrible would be to store allocation information on the DynamicObject iself, instead of on a separate Hash which leaks all allocations done while enabled.
=> But with trace_object_allocations_clear that is not so simple.

Self-note: the memory_profiler uses ObjectSpace.trace_object_allocations_start

require_relative '../../spec_helper'
require 'objspace'

describe "ObjectSpace.memsize_of_all" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs of this say:

This method is only expected to work with C Ruby.

But it seems we already implement it.
Anyway I think adding specs for it is fine, it doesn't seem worse than ObjectSpace.each_object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We implement quite a bit more of objspace in random ways.

describe "ObjectSpace.memsize_of_all" do
it "returns a non-zero Integer for all objects" do
ObjectSpace.memsize_of_all.should be_kind_of(Integer)
ObjectSpace.memsize_of_all.zero?.should be_false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectSpace.memsize_of_all.should > 0 seems more expressive and clearer, I'll change to that.

@eregon eregon added the in-ci The PR is being tested in CI. Do not push new commits. label Jul 15, 2021
@chrisseaton
Copy link
Collaborator Author

trace_object_allocations_clear could set a generation flag, and allocation information would be tagged with the current flag.

But as you say, not really worth improving it unless a need is seen. I'm fixing a crash here, that's all.

@eregon
Copy link
Member

eregon commented Jul 15, 2021

trace_object_allocations_clear could set a generation flag, and allocation information would be tagged with the current flag.

I had the same idea and implemented that.

@eregon eregon added this to the 21.3.0 milestone Jul 15, 2021
graalvmbot pushed a commit that referenced this pull request Jul 15, 2021
…cing information directly on RubyDynamicObject (#2403)

PullRequest: truffleruby/2804
@graalvmbot graalvmbot merged commit d5b0c3b into oracle:master Jul 15, 2021
@chrisseaton chrisseaton deleted the objspace branch July 27, 2021 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug in-ci The PR is being tested in CI. Do not push new commits. oca-signed shopify Pull requests from Shopify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants