Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

High-performance Ruby: Faster Symbol.to_s

DZone's Guide to

High-performance Ruby: Faster Symbol.to_s

·
Free Resource
Here's something that I found useful for shaving a few microseconds off. The performance gain ranges between 10% and 35%! YMMV.

Note: updated with suggestion by trans.


class Symbol
  def to_s
    @str_rep || (@str_rep = id2name.freeze)
  end
end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}