Jump to ratings and reviews
Rate this book

Addison-Wesley Professional Ruby Series

Professional Ruby Series Writing Efficient Ruby Code

Rate this book
This is the eBook version of the printed book.This short cut focuses on a number of coding patterns that are useful when trying to get maximum speed out of performance-critical sections of Ruby code. Anti-patterns, that is, coding idioms, which should be avoided in performance-sensitive code sections are discussed, including details on how to transform such code to make it more efficient. Most patterns were extracted from Stefan Kaes' work on improving performance of the Rails core and his regular Rails performance consulting work. These patterns are largely non-algorithmic, detailing local code transformations to achieve identical results with slightly different and faster code, as even local code changes can sometimes result in orders of magnitude improvements. Some patterns are useful independent of Rails' implementation language, but some of them are specific to Ruby, or more specifically, the current implementation of Ruby. Converts from other languages, especially from statically typed languages such as Java or C++ may find this material useful, as the performance characteristics of certain operations, like performing a function call or accessing object fields/attributes, are quite different from what you expect.What This Short Cut CoversIntroductionRuby's Interpreter Is SlowRuntime Complexity of Ruby Language ConstructsPatternsInstance Variables versus AccessorsLocal Variables Are CheapAssignments in ExpressionsInterpolated StringsIn-Place UpdatesSets versus ArraysFor Loops versus eachMake Decisions at Load TimeSelf Modifying CodeTest Most Frequent Case FirstOptimize Access to Global ConstantsCaching Data in InstanceVariablesCaching Data in Class VariablesCoding Variable Caching EfficientlyInitializing Variables with nilUsing .nil?nil? or empty? versus blank?Using returnUsing returningUsing any?Block Local VariablesDate FormattingTemporary Datastructure ConstantsFile System AccessObjectSpace.each_objectUnnecessary Block ParametersSymbol.to_procChained Calls of mapRequiring Files DynamicallyIncluding Modules versus Opening ClassesAbout the Author

50 pages

First published November 8, 2007

8 people want to read

About the author

Stefan Kaes

3 books1 follower

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
0 (0%)
4 stars
0 (0%)
3 stars
1 (100%)
2 stars
0 (0%)
1 star
0 (0%)
No one has reviewed this book yet.

Can't find what you're looking for?

Get help and learn more about the design.