owned this note
owned this note
Published
Linked with GitHub
# RubyKaigi 2024: The depths of profiling Ruby
すごく改稿エディション
Useful profilers are capable of accurately tracking program execution and providing sleek visualization, with minimal performance impact. When it comes to Ruby profilers, advanced features such as merging Ruby-level and C-level stacks or recording GC / GVL events would be also wanted.
There were many challenges in implementing these features in Pf2, my experimental Ruby profiler. In this talk, I will visit the internals of CRuby and present the difficulties in creating a profiler for the interpreter.
In this talk, I'll discuss the difficulties of creating a Ruby profiler through exploring the internals of CRuby, and introduce Pf2's design choices to overcome challenges. Let us discuss the future of profiling Ruby!
---
Good programs are fast. Good profilers are essential to writing one.
In this talk, I'll introduce my journey of creating Pf2, an “evolved” Ruby profiler. Pf2 accurately records thread-level program execution, provides improved visualization, captures GC / GVL events, and is even capable of combining C-level stacks with Ruby stacks (really useful with C extensions!).
There were many design decisions and implementation challenges. How to collect backtraces – through tracing or sampling, in-process or out-of-process? Minimizing performance impact? What types of visualizations could be offered?
By the end, you will know the internals of profilers enough to build your own. Let us discuss the future of profiling Ruby!
---
<details>
<summary>For Review Committee</summary>
## Details
Many programmers know how to use profilers, but not everyone knows how to build one.
In this talk, I plan to cover the following content:
- A brief introduction to performance profiling
- Basic concepts
- How to use visualization
- Why I built a new profiler
- The underlying technology of Pf2
- Design decisions in Pf2
- Sampling vs. Tracing / In-process vs Out-of-process
- Visualization using Firefox Profiler
- Event collection (GC / GVL, custom markers)
- The implementation of features exclusive to Pf2
- Tracking of per-thread CPU time consumption
- Consolidating (merging) Ruby backtrace and C backtrace
- ref: https://github.com/osyoyu/pf2/pull/6
- BPF integration (if done by May?)
- Evaluating accuracy and measuring performance penalty
- Comparisons against existing Ruby profilers
- ruby-prof (tracing, in-process), stackprof (samping, in-process), rbspy (sampling, out-of-process)
- Discuss what can be done further in profiler development to enable better profiling
- Through comparisons with other languages' profilers
- Bonus tracks, if there is enough time
- Profiling a real-world application
Intended audience:
- Intermediate+ level Ruby programmers
- Those who know how to use profilers to find hotspots and bottlenecks
- Those interested how "hotspots" are defined, and how profilers find them
## Pitch
I have been recently working on my experimental Ruby profiler [Pf2](https://github.com/osyoyu/pf2) under the support of the Ruby Association Grant. I am hoping to set a new standard of Ruby profiling through the development of Pf2, and performance people at RubyKaigi would be interested in such a topic.
Through my research during the Grant program, I have learned that there are many technical approaches towards creating profilers. There is no single correct answer. I will share my findings in my talk, and I'm expecting to discuss what choices could be made for the entire Ruby community to benefit.
While my talk is constructed to discuss the internals of the profiler, it's not that fellow Rubyists in general would be out of the loop. I do understand that not all RubyKaigi participants would create their own profiler, but many of them would be profiler users. After all, it's impossible to write good programs without knowing the users.
Also, learning how profilers work is directly connected to learning how to efficiently use profilers, and the session content should be direct takeaways for those who wish to write efficient programs.
Pf2 implementation progress can be found in GitHub https://github.com/osyoyu/pf2 .
Some content to be covered in this talk is compiled in my Scrapbox project https://scrapbox.io/pf2/ .
</details>
---
This is a copy of the Google Doc version.
https://docs.google.com/document/d/1UMUuUUPJsUSAToqdZM7r-kHHsFMYb9s7iATMDkGFBgM/edit