Ruby

Summarized using AI

Ruby Objects: A Walkabout

Terence Lee • March 05, 2015 • Earth

In the video titled "Ruby Objects: A Walkabout," Terence Lee discusses the intricacies of Ruby objects, focusing on tools and techniques to analyze Ruby applications. The session emphasizes the use of Ruby's TracePoint API and ObjectSpace API for introspecting and debugging Ruby applications. Terence begins by introducing himself, highlighting his experience with Ruby and role at Heroku, where he has contributed to maintaining Ruby versions and development tools.

The key points covered in the talk are as follows:

  • Introduction to Ruby Tools: Terence explains the motivation behind looking deeper into Ruby objects and describes his background involving introspection techniques in Ruby, especially his experiences with JRuby.

  • TracePoint API: Introduced in Ruby 2.0, the TracePoint API provides a more object-oriented approach to tracing events in Ruby applications. Terence demonstrates how to utilize the TracePoint to gather insightful data about method calls, class instantiations, and thread activity while cautioning about potential performance impacts in production environments.

  • ObjectSpace API: Terence introduces the ObjectSpace API, which enables developers to track and analyze object sizes in memory. This tool can help developers count and inspect objects within their applications, allowing for a closer look at memory usage and the types of objects created.

  • Allocation Tracer Gem: An extension of the ObjectSpace API that simplifies the tracking of object allocations. This gem is beneficial for identifying specific lines of code responsible for excessive object allocation, thus helping in performance optimization and debugging.

  • Practical Implementation: Terence discusses combining these tools for deeper insights into Ruby application performance and memory allocation. He stresses the importance of measuring memory consumption in complex applications and recognizes the potential pitfalls of using these tools within large codebases.

  • Conclusion and Takeaways: Terence wraps up by encouraging developers to experiment with the presented tools. He acknowledges that while these introspection tools may not be as advanced as some external applications, they are highly effective for understanding and optimizing Ruby code, emphasizing community input for future improvements.

Overall, this talk provides a comprehensive overview of the Ruby object model and offers practical methods for diagnosing and improving Ruby applications. Terence's insights make it clear that the right use of built-in tools can significantly aid developers in performance enhancement efforts.

Ruby Objects: A Walkabout
Terence Lee • March 05, 2015 • Earth

By, Terence Lee
In Ruby, it's easy to create classes, methods, and objects. For instance, did you know that a hello world sinatra app uses 43 classes, 155 methods, and dispatches 548 methods for a single request. In this talk, we're going use TracePoint API to look at how you can find out this information among other things. Additionally, now that we have all these objects from our Ruby app, the evolving ObjectSpace API we can glean information about rough object size in memory. Let's take a walk through objects in Ruby.

Help us caption & translate this video!

http://amara.org/v/GUQG/

Ruby on Ales 2015

00:00:29.679 I would like to introduce this gentleman in the blue hat. The 'H' on his hat stands for Heroku, which is where he works, and it's also his Twitter handle. That's why he wears the hat. I'm pretty sure I'm not a sports person, but I think that's what it is. Terence and I have been friends for a reasonably long time. We met at the first Ruby on Ales, which I believe was his first speaking gig. I was impressed because he's a snappy dresser like me, so we got along right away.
00:00:44.160 He works at Heroku, as I mentioned. Additionally, he has maintained two Ruby versions simultaneously: 1.8.7 and 1.9.2. May they rest in peace. He also collaborated with Zangief on one of his early Ruby projects when he was just starting out. Together, Terence and Zangief worked on those Ruby versions.
00:01:03.440 If anyone has used Heroku, you have used Terence's code because he wrote and maintains the build packs. While there may be more to the build packs than just Terence's code, he was instrumental in their development. Furthermore, I'd like to mention that Terence started organizing a conference last year in Austin called 'Keep Ruby Weird.' For the record, ‘Keep Austin Weird’ originated from Portland; that was a Portland initiative. We invented it, and now it has permeated to others, including Austin, which is something to note. I'm going to update the Wikipedia article about that!
00:01:35.119 I attended 'Keep Ruby Weird' last year, and it was fantastic. They had a lovely mascot named Roadie. If you get a chance, you should definitely go to 'Keep Ruby Weird.' It's a lot of fun, and it has a very similar feel to Ruby on Ales, with many close-knit people hanging out. So, without further ado, let's give a big round of applause for Terence.
00:02:10.319 This is a picture of Jonah sitting on Roadie during our socialization practices at ‘Keep Ruby Weird.’ This is my third time speaking at Ruby on Ales, and I still get really nervous. So, I asked John for help, and he told me to put this slide up to make me feel a little better about it. I'm here to talk to you about Ruby objects.
00:02:37.360 When I think about walkabouts, I often think of Australia—that notion comes from there. This is me at RubyConf Australia, where I was supposed to do a Friday hug, but unfortunately, the organizers didn't schedule me for that. However, I hope Ernie will be able to take over that task tomorrow. My Twitter handle is @hohno2. As Joan mentioned, I come from Austin, Texas, a place famous for great tacos. I picked Joan up at the airport when he came into town and took him to some pretty awesome tacos.
00:03:17.200 In addition to tacos, Austin is also known for having excellent barbecue. We took a bunch of speakers to Franklin BBQ, a famous barbecue restaurant in Austin. However, here is a picture of Jonah not getting into the barbecue place because there was about a five-hour wait. Eventually, he did get in and enjoyed some delicious barbecue!
00:04:38.240 As mentioned, I always wear my blue hat, but I don't really know why that hat has become synonymous with me. It's simply a college hat, and they don't sell them anymore. You might wonder what I will do if I ever lose this hat. I don't have a definitive answer, but I do have some hat stickers left. If you would like one, feel free to come talk to me, and I'd be more than happy to share!
00:05:10.080 I work at Heroku and have been there for almost five years now. They allow me to work on open source and a variety of Ruby-related projects, including maintaining Ruby versions 1.8.7 and 1.9.2 alongside Zach, as well as working on Bundler and other initiatives. I'm very appreciative of our customers and the chance to do meaningful work. So, if anything is broken on Heroku, especially anything related to Ruby, it is my fault, so feel free to voice your frustrations to me about that.
00:06:45.280 One of the fantastic people I get to work with is Richard Schneeman. If you haven’t heard of him, he’s accomplished a lot recently, including getting a commit to Rails. He just celebrated three years at Heroku, and if you haven’t voted for Ruby Heroes yet, the voting ends in four days. You should definitely consider voting for Richard for all the significant work he has done. He also implemented a patch for Rack that improved memory consumption by five percent across all Rack applications, just one example of his many contributions.
00:07:37.760 In addition to Richard, I also want to mention Zangief. I promised him I would be his Ruby Heroes campaign manager this past year. Since 2013, I have included a slide about him in every talk I’ve given. He has put in a lot of effort, especially regarding maintaining Ruby documentation and many other projects. I know he spends countless nights and weekends working on these initiatives, so let’s give him a round of applause too! But now, let’s proceed to the main part of my talk.
00:09:57.120 I’ve attended many Ruby talks focused on introspection and related topics. Davey once delivered an amazing talk on benchmarking. A good friend of mine benchmarks everything against the Fibonacci algorithm, but I’m not here to talk about Fibonacci or benchmarking. My background includes some job development experience, and I’ve worked with JRuby, which has impressive enterprise tools that allow you to gather detailed insights into production applications.
00:10:23.840 Today, I want to explore some tools we have in Ruby that may not be as advanced but help you improve your Ruby applications. I will be discussing the TracePoint API, ObjectSpace, and the allocation tracer gem.
00:10:56.400 Looking at TracePoint, it was introduced in Ruby 2.0. Before TracePoint, we had Kernel#set_trace_func, allowing you to set a trace function that filters events like calls and returns. This was useful as you could analyze events happening in Ruby code.
00:11:11.760 With TracePoint, we have a more Object-Oriented approach. For example, to depict the same functionality we previously had with set_trace_func, we create a new TracePoint object and utilize its methods. This way, we can filter events to trace, such as method calls, class instantiation, and threads.
00:12:05.760 When utilizing TracePoint, keep in mind that it tracks every single event, which may significantly affect performance, especially in production environments. However, if you are trying to debug issues such as memory leaks or performance concerns, these insights are beneficial. Since the adoption of Ruby 2.0, TracePoint has allowed developers to introspect their applications in a more efficient manner.
00:13:04.959 In Ruby, if we want to analyze the size of specific objects in memory, the ObjectSpace API helps us achieve this. The ObjectSpace API enables the counting and inspecting of objects within Ruby, offering methods for iteration and analyzing the memory consumed by certain types.
00:13:58.560 This allows us to gather statistics regarding the types of objects our applications utilize. However, caution is advised; traversing every object in large applications may lead to performance drawbacks.
00:15:53.840 An extension of ObjectSpace is the allocation tracer gem. This gem simplifies the process of tracking object allocations, allowing us to view where and how many objects are being instantiated. By combining allocation tracking with previous introspection methods, we gain deeper insights into memory usage.
00:17:10.720 By conducting object allocation analysis, we can pinpoint specific lines of code responsible for many allocations. This knowledge supports performance enhancements and can significantly aid in debugging processes, particularly in complex applications.
00:19:31.839 In summary, we have several tools at our disposal to analyze and debug Ruby applications. While it might not be as advanced as some external tools like JVisualVM, these methods provide tremendous assistance in understanding and optimizing Ruby code. If you have ideas or additional features you think are necessary for improving introspection in Ruby, don't hesitate to share.
00:20:39.840 This concludes my talk. It's lunchtime now!
Explore all talks recorded at Ruby on Ales 2015
+9