64 ms·
Sam is a smart guy and an awesome developer. He contributed tons of code for .NET community when he worked at Stack Overflow. I have done a fair amount of perf
by solutionyogi 12y ago
Sam is a smart guy and an awesome developer. He contributed tons of code for .NET community when he worked at Stack Overflow.
I have done a fair amount of performance optimization work in .NET/C#, so I was curious as to what kind of optimizations are involved in Ruby.
One of the optimization was this:
https://github.com/SamSaffron/rails/commit/9aa2b2d7bf52c0f3974090cd033341be2edeae6d https://github.com/SamSaffron/rails/commit/9aa2b2d7bf52c0f39...
Three lessons:
1. Always use profiler to identify code bottlenecks. I don't think I would have ever guessed that the string literal is costing memory allocations causing performance issues.
2. I find it sad that this kind of optimization is required in 2015. In any statically typed language, this would be completely unnecessary.
3. Performance optimization makes code less readable. I think it would make sense to add comment explaining why constant ID was declared.
Here's another:
https://github.com/SamSaffron/rails/commit/a668b09ee387bf241a3481a764a18a5c8a4df8cd https://github.com/SamSaffron/rails/commit/a668b09ee387bf241...
Same story.
- m0th87 12y agoString interning has nothing to do with static typing. AFAIK Ruby supports it with symbols and Python with strings in general.
- riffraff 12y agoRecent rubys also supports it for frozen strings (which is the reason it's a frozen string in the commit, probably). The reason it's not done by default is that with mutable strings it would be more complicates/would require a different string implementation, I guess.