Ruby Frozen String Literals Do Not Result in Any Performance Improvement
Frozen string literals is the experimental feature that appeared in Ruby 2.3 and will become the default behavior in Ruby 3.0. There's been some talk about how that improves performance. A month ago I ported one of my applications and saw no improvement. Today took another look, and my conclusion still stands.
If you haven't heard about frozen string literals yet, please read my previous blog post to learn more about how they work.
When I last experimented with this feature, my conclusion was that it only adds to the developer's frustration. It's just more work for us to port our applications.
I finally found the time to port Acunote, the application that has decent performance benchmarks. Let's look at some of my before/after measurements:
Benchmark | Default Behavior | Frozen String Literals |
---|---|---|
Benchmark Burndown 120 | 0.91 ± 0.02 | 0.91 ± 0.02 |
Benchmark Sprint 20 x (1+5) (C) | 0.25 ± 0.00 | 0.25 ± 0.01 |
Benchmark Analyze 20 x (1+5) | 1.96 ± 0.02 | 1.95 ± 0.04 |
Benchmark Task Details Page | 0.40 ± 0.01 | 0.41 ± 0.01 |
Benchmark Signup | 0.30 ± 0.00 | 0.31 ± 0.01 |
Benchmark Copy 120 | 1.47 ± 0.01 | 1.51 ± 0.02 |
Benchmark Import 71 | 2.02 ± 0.02 | 2.10 ± 0.01 |
Benchmark Set Field (EP) | 0.20 ± 0.00 | 0.21 ± 0.00 |
This table is incomplete. The whole performance test suite has more than 60 benchmarks. But not one of them indicated any statistically significant speedup. Worse, the performance actually declined in two of the benchmarks that I highlighted in the table.
I haven't investigated the causes of the slowdown yet, but the conclusion is clear. Frozen string literals do not improve performance of my Rails applications.
The word
Did you like this post? Follow me on Twitter or Google+ to stay updated on Ruby performance optimization news.
Previous: | $6 Discount on Ruby Performance Optimization Book (Paperback) Today on Amazon |