Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby: extension types should define a proper memsize function #10280

Closed
casperisfine opened this issue Jul 20, 2022 · 4 comments · Fixed by #15811
Closed

Ruby: extension types should define a proper memsize function #10280

casperisfine opened this issue Jul 20, 2022 · 4 comments · Fixed by #15811
Assignees
Labels
enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. ruby

Comments

@casperisfine
Copy link
Contributor

Here's an snippet from a Ruby heap dump (generated with ObjectSpace.dump_all

{"address":"0x7fa2dadd7320", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}
{"address":"0x7fa2dadd1678", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}
{"address":"0x7fa2dadd3c70", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}
{"address":"0x7fa2dadcfaa8", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}
{"address":"0x7fa2dadc9c98", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}
{"address":"0x7fa2dadcb390", "type":"DATA", "class":"0x7fa3eb7ab408", "struct":"Google::Protobuf::Internal::Arena", "memsize":40}

As you can see, all these Google::Protobuf::Internal::Arena instances claim to be 40 bytes, which is obviously a lie.

This is because the memsize function is not defined:

{Arena_mark, Arena_free, NULL},

What language does this apply to?

Ruby

Describe the problem you are trying to solve.

I'd like to have a semi-accurate idea of how much memory the google-protobuf gem is holding onto.

Describe the solution you'd like

I'd like these functions to be defined (Arena, Message, etc). They don't have to be 100% accurate, not particularly fast. It's a debugging facility.

Describe alternatives you've considered

I don't see any.

cc @zhangskz because #9384 (comment)

@casperisfine casperisfine added the untriaged auto added to all issues by default when created. label Jul 20, 2022
@zhangskz
Copy link
Member

This makes sense and would be helpful as a whole for debugging and understanding memory usage.

We previously investigated implementing dsize which similarly allows extensions to report the object's memory per ruby extension documentation when addressing memory leak #9467.

Implementing a trivial dsize that reported a large number didn't help trigger more frequent GC so we didn't pursue this further at the time, but this is still useful for profiling memory used by Arena objects.

@zhangskz zhangskz removed the untriaged auto added to all issues by default when created. label Jul 20, 2022
@casperisfine
Copy link
Contributor Author

We previously investigated implementing dsize which similarly allows extensions to report the object's memory

That's the same thing.

Implementing a trivial dsize that reported a large number didn't help trigger more frequent GC

Yes it's purely for introspection. To notify the GC of allocations, you need to use the ruby malloc functions.

casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Jul 21, 2022
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Jul 21, 2022
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Aug 3, 2022
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Aug 3, 2022
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Aug 10, 2022
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Feb 17, 2023
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
casperisfine pushed a commit to casperisfine/protobuf that referenced this issue Feb 28, 2023
Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the
memory used by these objects.

It's useful when running memory profilers against applications.
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Jan 14, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2024
copybara-service bot pushed a commit that referenced this issue Feb 13, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
FUTURE_COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606424604
copybara-service bot pushed a commit that referenced this issue Feb 13, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
FUTURE_COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606424604
copybara-service bot pushed a commit that referenced this issue Feb 13, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
FUTURE_COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606424604
copybara-service bot pushed a commit that referenced this issue Feb 13, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
FUTURE_COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606424604
copybara-service bot pushed a commit that referenced this issue Feb 13, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606718632
zhangskz pushed a commit that referenced this issue Feb 14, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606718632
zhangskz pushed a commit that referenced this issue Feb 14, 2024
Fix: #10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes #10291

COPYBARA_INTEGRATE_REVIEW=#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606718632
deannagarcia pushed a commit to deannagarcia/protobuf that referenced this issue Jun 20, 2024
)

Fix: protocolbuffers#10280

This allows Ruby to report a more correct estimation of the memory used by these objects.

It's useful when running memory profilers against applications.

cc @zhangskz @haberman

Closes protocolbuffers#10291

COPYBARA_INTEGRATE_REVIEW=protocolbuffers#10291 from casperisfine:ruby-sizes 9150795
PiperOrigin-RevId: 606718632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. ruby
Projects
None yet
3 participants