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

Expose StackTable to Ruby #62

Merged
merged 30 commits into from
Apr 11, 2024
Merged

Expose StackTable to Ruby #62

merged 30 commits into from
Apr 11, 2024

Conversation

jhawthorn
Copy link
Owner

@jhawthorn jhawthorn commented Apr 7, 2024

StackTable exposes Vernier's (previously internal) method of collecting stacks and frames without making Ruby allocations and returns a single integer representing a unique stack.

stack_table = Vernier::StackTable.new
stack_table.current_stack #=> 12
stack_table.current_stack #=> 13

This can later be decoded

stack_table.backtrace(12)
#=> ["test.rb:5:in 'foo'",
#    "test.rb:9:in 'bar'"]

The first use of this can be collecting stack indexes which are compatible with the output of Vernier's collectors (ex. to add them to markers). The second is performance.

This is 2-3x faster than using caller_locations, however the biggest gains would be when additional processing is done on the stack in Ruby (ex. filtering or reformatting) which can be avoided because stacks and frames are de-duplicated.

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
Warming up --------------------------------------
              caller    28.485k i/100ms
    caller_locations   110.542k i/100ms
stack_table.current_stack
                       303.853k i/100ms
Calculating -------------------------------------
              caller    283.979k (± 0.3%) i/s -      1.424M in   5.015382s
    caller_locations      1.128M (± 0.2%) i/s -      5.748M in   5.094051s
stack_table.current_stack
                          3.064M (± 0.2%) i/s -     15.497M in   5.057551s

@jhawthorn jhawthorn merged commit 30bb3f3 into main Apr 11, 2024
7 checks passed
@jhawthorn jhawthorn deleted the stack_table branch April 11, 2024 03:26
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