SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Ruby/Rails Performance Tips
Patrick McSweeny
About Me
 I really like Ruby
 Organizer of Ann Arbor Ruby Brigade
 Looking for speakers
Notes on format
 Briefly touch on many different topics
 Self-study encouraged
When to Optimize for Performance
 Application is running slowly
 High resource consumption
 Hosting is getting expensive
 Need to scale
When Not to Optimize
 Still a beginner
 Early stages of application development
 Limited number of users for app
Background on Ruby
 High level language
 Memory allocations handled by interpreter
 Garbage collector frees up unused memory
 Crucial for limiting memory consumption
 Resource intensive
Use the latest version of Ruby possible
Use Newer Rubies
 Significant performance improvements with
each version
 Reduced memory consumption
 Garbage collection is more efficient
 Rails 4.2.8 and up is compatible with Ruby 2.4
How to Speed Up Ruby
Avoid using temporary variables
 Cuts down on memory consumption
 Modify variables in place
 ex: str.downcase! instead of new = str.downcase
 Chain methods together (i.e. functional
programming)
 ex: str.downcase.reverse!
Dive into the Enumerable Module
 Use map or map! to run the same method on all
items in collection

Dive into the Enumerable Module
 Use .reject/delete_if? to delete items from
collection
 Use .any? instead of .count > 0
Use a Lightweight Stack
 Sinatra - Ruby DSL for web framework
 Cuba – Super-lightweight web framework in
pure Ruby
 Mote – Lightweight templating engine
Use a Lightweight Stack
 Use only what you need from Rails
 Use ActiveRecord by itself
 Create your own model layer
 Use API Controller for returning JSON
 Create your own controller
 ActionController consists of
 Metal – bare-bones controller class
 A bunch of included modules
 Use Metal Class and only include modules you need
Write Less Ruby
 Create gems that use low level language
 C/C++ - not for beginners
 Rust – low-level programming done safely

Take the logic
and put it in the database
Fast Scalable
Ruby
Databases
✓ ✓
Put the logic in the database
 Write custom queries for advanced needs
 Joins
 Sub-queries
 Aggregate (group by) functions
 Math
 Custom database functions
 Database views (named queries)
 Downside is logic is in two different places
Alternative Implementations of Ruby
 JRuby – good for heavy loads
 Rubinius – modern approach to implementation
Speeding up Rails
 Understand queries executed by ActiveRecord
 ex: Use author.book_ids instead of
author.books.pluck(:id)
 Use sub-queries, other advanced SQL techniques
 Eager load associations
 ex: books = Book.includes(:author).all
 Cuts down on total number of queries executed
 Prevents n + 1 queries

Caching
 Page caching – not very flexible
 Action caching – runs filters such as
authentication before loading page
 Fragment Caching
Russian Doll Caching
 New in Rails 5
 Cache fragment inside a cache fragment – and
so on
 Child object cache expiration triggers parent
object cache expiration

Russian Doll Caching
Speeding Up Rails
 Limit use of loops in ActiveRecord
 Pass array of hashes to create method
 Use update_all
 destroy_all/delete_all
Speeding Up Rails
 Render a collection of objects in partials all at
once
 ex:
Speeding Up Rails
 Clean up routes file
 Information in file is parsed on every request app
receives
 Put most used routes at the top
 Limit auto-generated routes with only and except
params
 ex: resources :books, only: [:index, :show]
@PatrickMcSweeny

Weitere ähnliche Inhalte

Was ist angesagt?

Brief introduction to Distributed Deep Learning
Brief introduction to Distributed Deep LearningBrief introduction to Distributed Deep Learning
Brief introduction to Distributed Deep LearningAdam Gibson
 
Aerospike - fast and furious caching @ Burgasconf 2016
Aerospike - fast and furious caching @ Burgasconf 2016Aerospike - fast and furious caching @ Burgasconf 2016
Aerospike - fast and furious caching @ Burgasconf 2016Tihomir Trifonov
 
From rest api to graph ql a 10 year journey
From rest api to graph ql a 10 year journeyFrom rest api to graph ql a 10 year journey
From rest api to graph ql a 10 year journeyArno Schulz
 
Web Performance Part 3 "Server-side tips"
Web Performance Part 3  "Server-side tips"Web Performance Part 3  "Server-side tips"
Web Performance Part 3 "Server-side tips"Binary Studio
 
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...ScyllaDB
 
Workers and Worker Patterns at Scale
Workers and Worker Patterns at ScaleWorkers and Worker Patterns at Scale
Workers and Worker Patterns at ScaleChad Arimura
 
MySQL-Mixer-Livenation
MySQL-Mixer-LivenationMySQL-Mixer-Livenation
MySQL-Mixer-LivenationHari Tatrakal
 
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...LogeekNightUkraine
 
Machine Learning for (JVM) Developers
Machine Learning for (JVM) DevelopersMachine Learning for (JVM) Developers
Machine Learning for (JVM) DevelopersMateusz Dymczyk
 

Was ist angesagt? (13)

Brief introduction to Distributed Deep Learning
Brief introduction to Distributed Deep LearningBrief introduction to Distributed Deep Learning
Brief introduction to Distributed Deep Learning
 
Aerospike - fast and furious caching @ Burgasconf 2016
Aerospike - fast and furious caching @ Burgasconf 2016Aerospike - fast and furious caching @ Burgasconf 2016
Aerospike - fast and furious caching @ Burgasconf 2016
 
Drupal Performance
Drupal PerformanceDrupal Performance
Drupal Performance
 
From rest api to graph ql a 10 year journey
From rest api to graph ql a 10 year journeyFrom rest api to graph ql a 10 year journey
From rest api to graph ql a 10 year journey
 
Apache pulsar
Apache pulsarApache pulsar
Apache pulsar
 
Web Performance Part 3 "Server-side tips"
Web Performance Part 3  "Server-side tips"Web Performance Part 3  "Server-side tips"
Web Performance Part 3 "Server-side tips"
 
Repository 3.7
Repository 3.7Repository 3.7
Repository 3.7
 
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...
Scylla Summit 2018: Rebuilding the Ceph Distributed Storage Solution with Sea...
 
Workers and Worker Patterns at Scale
Workers and Worker Patterns at ScaleWorkers and Worker Patterns at Scale
Workers and Worker Patterns at Scale
 
MySQL-Mixer-Livenation
MySQL-Mixer-LivenationMySQL-Mixer-Livenation
MySQL-Mixer-Livenation
 
Scrappy
ScrappyScrappy
Scrappy
 
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...Sergei Nesterov  "How to Speed Up the Build of Large Projects. Overview and C...
Sergei Nesterov "How to Speed Up the Build of Large Projects. Overview and C...
 
Machine Learning for (JVM) Developers
Machine Learning for (JVM) DevelopersMachine Learning for (JVM) Developers
Machine Learning for (JVM) Developers
 

Ähnlich wie Ruby/Rails Performance Tips

Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroadJim Jones
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoadwebuploader
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesJon Meredith
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBRick Copeland
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityAshok Modi
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & CucumberUdaya Kiran
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceAshok Modi
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails FinalRobert Postill
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupJose de Leon
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 

Ähnlich wie Ruby/Rails Performance Tips (20)

Rails Concept
Rails ConceptRails Concept
Rails Concept
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL Databases
 
MongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDBMongoATL: How Sourceforge is Using MongoDB
MongoATL: How Sourceforge is Using MongoDB
 
Drupal Backend Performance and Scalability
Drupal Backend Performance and ScalabilityDrupal Backend Performance and Scalability
Drupal Backend Performance and Scalability
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on Rails
Ruby on Rails Ruby on Rails
Ruby on Rails
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
DrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performanceDrupalCampLA 2011: Drupal backend-performance
DrupalCampLA 2011: Drupal backend-performance
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User Group
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
Ruby and Security
Ruby and SecurityRuby and Security
Ruby and Security
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on rails for beginers
Ruby on rails for beginersRuby on rails for beginers
Ruby on rails for beginers
 

Kürzlich hochgeladen

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Kürzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Ruby/Rails Performance Tips

  • 2. About Me  I really like Ruby  Organizer of Ann Arbor Ruby Brigade  Looking for speakers
  • 3. Notes on format  Briefly touch on many different topics  Self-study encouraged
  • 4. When to Optimize for Performance  Application is running slowly  High resource consumption  Hosting is getting expensive  Need to scale
  • 5. When Not to Optimize  Still a beginner  Early stages of application development  Limited number of users for app
  • 6. Background on Ruby  High level language  Memory allocations handled by interpreter  Garbage collector frees up unused memory  Crucial for limiting memory consumption  Resource intensive
  • 7. Use the latest version of Ruby possible
  • 8. Use Newer Rubies  Significant performance improvements with each version  Reduced memory consumption  Garbage collection is more efficient  Rails 4.2.8 and up is compatible with Ruby 2.4
  • 9. How to Speed Up Ruby
  • 10. Avoid using temporary variables  Cuts down on memory consumption  Modify variables in place  ex: str.downcase! instead of new = str.downcase  Chain methods together (i.e. functional programming)  ex: str.downcase.reverse!
  • 11. Dive into the Enumerable Module  Use map or map! to run the same method on all items in collection 
  • 12. Dive into the Enumerable Module  Use .reject/delete_if? to delete items from collection  Use .any? instead of .count > 0
  • 13. Use a Lightweight Stack  Sinatra - Ruby DSL for web framework  Cuba – Super-lightweight web framework in pure Ruby  Mote – Lightweight templating engine
  • 14. Use a Lightweight Stack  Use only what you need from Rails  Use ActiveRecord by itself  Create your own model layer  Use API Controller for returning JSON  Create your own controller  ActionController consists of  Metal – bare-bones controller class  A bunch of included modules  Use Metal Class and only include modules you need
  • 15. Write Less Ruby  Create gems that use low level language  C/C++ - not for beginners  Rust – low-level programming done safely 
  • 16. Take the logic and put it in the database
  • 18. Put the logic in the database  Write custom queries for advanced needs  Joins  Sub-queries  Aggregate (group by) functions  Math  Custom database functions  Database views (named queries)  Downside is logic is in two different places
  • 19. Alternative Implementations of Ruby  JRuby – good for heavy loads  Rubinius – modern approach to implementation
  • 20. Speeding up Rails  Understand queries executed by ActiveRecord  ex: Use author.book_ids instead of author.books.pluck(:id)  Use sub-queries, other advanced SQL techniques  Eager load associations  ex: books = Book.includes(:author).all  Cuts down on total number of queries executed  Prevents n + 1 queries 
  • 21. Caching  Page caching – not very flexible  Action caching – runs filters such as authentication before loading page  Fragment Caching
  • 22. Russian Doll Caching  New in Rails 5  Cache fragment inside a cache fragment – and so on  Child object cache expiration triggers parent object cache expiration 
  • 24. Speeding Up Rails  Limit use of loops in ActiveRecord  Pass array of hashes to create method  Use update_all  destroy_all/delete_all
  • 25. Speeding Up Rails  Render a collection of objects in partials all at once  ex:
  • 26. Speeding Up Rails  Clean up routes file  Information in file is parsed on every request app receives  Put most used routes at the top  Limit auto-generated routes with only and except params  ex: resources :books, only: [:index, :show]