Skip to content

ruby: add skip_native_resume to avoid tail call exhaustion (upstream prep)#38

Draft
dalehamel wants to merge 5 commits intomainfrom
ruby-skip-native-resume-prep
Draft

ruby: add skip_native_resume to avoid tail call exhaustion (upstream prep)#38
dalehamel wants to merge 5 commits intomainfrom
ruby-skip-native-resume-prep

Conversation

@dalehamel
Copy link
Copy Markdown
Member

Rebased version of Shopify PR #31 for staging before upstream submission.

BPF blobs will need rebuilding.

@dalehamel dalehamel force-pushed the ruby-skip-native-resume-prep branch from 3f9c997 to 8b34059 Compare April 7, 2026 21:02
Copy link
Copy Markdown
Member Author

@dalehamel dalehamel left a comment

Choose a reason for hiding this comment

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


Review assisted by pair-review

When the Ruby unwinder encounters a cfunc (C-implemented Ruby method),
it normally transitions back to the native unwinder to unwind through
the C code, then re-enters the Ruby unwinder when it detects the Ruby
interpreter loop. Each such round-trip costs 2-3 tail calls out of a
budget of 29, so a Ruby stack with 10+ cfuncs can easily truncate.

This adds a skip_native_resume flag to RubyProcInfo that, when set,
pushes cfunc frames inline without transitioning to the native unwinder.
This trades native frames within cfuncs (e.g., the C call chain inside
Array#sort) for complete Ruby-level traces without truncation.

The flag is controlled by OTEL_EBPF_RUBY_SKIP_NATIVE_RESUME (default:
false). Set to 'true' to enable.
- Correct inline comment that incorrectly stated 'Default to skipping'
  when the actual default is false (requires explicit opt-in)
- Add note that skipNativeResume() is evaluated per-process at attach time
When skip_native_resume is true, the end-of-stack check should stop
instead of resuming native unwinding. Without this, the native unwinder
can re-enter the Ruby unwinder from JIT anonymous mappings, pushing
frames in wrong positions.
@dalehamel dalehamel force-pushed the ruby-skip-native-resume-prep branch from bbf12f7 to f947f92 Compare April 9, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant