Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
On a recent project, I sped up a test suite 15% by making a change to a single factory. This suite, like many others (including yours!), was making way too many database calls. It’s so easy to accidentally add extra queries to factories and test setup and these can compound to shockingly large numbers. The chaos is your opportunity! Learn to profile and fix hot spots, build big-picture understanding through diagrams, and write code that is resistant to extraneous queries. This talk will equip you to take back control of your build times and maybe impress your teammates in the process.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
This talk, presented by Joël Quenneville at RailsConf 2022, focuses on the common issue of test suites making excessive database calls, which leads to slower tests and longer feedback loops in the development process. To improve the performance of a test suite, it's crucial to identify and eliminate unnecessary database queries caused by test setup, support code, and production code. Key points discussed include: - **Impact of Slow Tests**: Slow tests create longer feedback loops and can severely delay deployments because developers wait for tests to execute. This results in lower confidence in tests as they are not run as frequently. - **Common Contributors to Slow Tests**: The speaker identifies three major sources that contribute to slow tests: HTTP requests, headless browser operations, and database queries. - Recommendations include disabling real network calls using tools like Webmock or VCR, utilizing a testing pyramid structure, and minimizing data persistence when unnecessary. - **Focus on Database Queries**: Specifically, the talk emphasizes reducing excessive database interactions during test setup. Even though individual queries may not be expensive, they accumulate over many tests and significantly slow down the entire suite. - **Test Setup Issues**: A primary problem is shared test setup, where tests unnecessarily create more data than required through inheritance of setups, leading to extra database calls. The importance of in-line setup is highlighted to avoid creating superfluous data. - **Challenges in Factories**: Factories can often introduce hidden complexity by creating associated records automatically, which can compound queries. The speaker recommends keeping factories minimal, only including necessary attributes, and using traits for extended setups where appropriate. - **Active Record Callbacks**: Callbacks can create unintentional data during object creation, complicating tests even further. It is crucial to manage these carefully to prevent excess database writes. - **Profiling and Debugging Strategies**: The speaker suggests tools such as SQL tracker and profiling gems to identify slow factories and the number of queries made. Diagrams and object graphs can help visualize the unnecessary data being created. - **Case Study**: Joël shares a case study where he improved a slow test suite by identifying and fixing overly complex factory relationships, achieving a 15% increase in test speed. In conclusion, improving test performance involves careful attention to how data is created in tests, optimizing setups, minimizing unnecessary queries, and leveraging profiling tools to identify hot spots. This both enhances team productivity and fosters a more efficient development process.
Suggest modifications
Cancel