From: "ivoanjo (Ivo Anjo) via ruby-core" Date: 2025-12-01T10:31:31+00:00 Subject: [ruby-core:123961] [Ruby Feature#21722] Expose rb_gc_mark_weak API for use in extensions Issue #21722 has been reported by ivoanjo (Ivo Anjo). ---------------------------------------- Feature #21722: Expose rb_gc_mark_weak API for use in extensions https://bugs.ruby-lang.org/issues/21722 * Author: ivoanjo (Ivo Anjo) * Status: Open ---------------------------------------- In https://bugs.ruby-lang.org/issues/21710 it came up that 1. On top of [deprecating _id2ref](https://bugs.ruby-lang.org/issues/15408) on Ruby 4.0, [it's a bad idea to be using object_id from the NEWOBJ tracepoint](https://bugs.ruby-lang.org/issues/21710#note-8) 2. `rb_gc_mark_weak` which would be the alternative for an extension that needs weak reference-like behavior [is not available for extensions](https://bugs.ruby-lang.org/issues/21710#note-9) So I've opened this ticket to request exposing `rb_gc_mark_weak` so it can be used by extensions? --- The [Datadog Ruby profiler](https://github.com/datadog/dd-trace-rb) is currently using object_id and id2ref to implement its "heap profiling" -- that is, we have a NEWOBJ tracepoint, and from time to time (e.g. not for every object), we select an object, and track its lifetime by keeping its id and checking from time to time if it's still alive. We're using this approach instead of: * The FREEOBJ event => Reduced overhead, as we don't need to be called for every object (+ not needing to deal with corner cases of when FREEOBJ may not be called for an object) * WeakMap => Weakmap APIs are Ruby-level and need the GVL, and thus make it hard to use from low-level tracepoints and to avoid overhead by doing profiler work with the GVL released. For our purposes, it would be OK if this API is not "official" -- e.g. if it's one of those that gets exposed as a public symbol but not documented and no promises made for future Ruby releases. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/