-
Notifications
You must be signed in to change notification settings - Fork 15
Optimize experiment pagination query performance #2860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: experiment-design-refresh
Are you sure you want to change the base?
Optimize experiment pagination query performance #2860
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR optimizes the /api/experiments/paginated endpoint by reducing unnecessary database JOINs and adding strategic indexes, addressing severe performance degradation (3.34s response time down to an estimated 300-500ms).
Changes:
- Reduced database JOINs from 20 to 3 in the
findPaginatedmethod by removing eager loading of nested relationships not required for the experiment list view - Added database indexes on frequently queried columns (updatedAt, state, name) and foreign keys
- Removed unnecessary data transformation methods that processed unused nested data
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/packages/Upgrade/src/api/services/ExperimentService.ts | Removed 17 unnecessary LEFT JOINs and data transformations from the paginated query |
| backend/packages/Upgrade/src/api/models/Experiment.ts | Added indexes for updatedAt, state, and name columns to optimize sorting and filtering |
| backend/packages/Upgrade/src/api/models/ExperimentCondition.ts | Added index on experiment foreign key to optimize JOIN performance |
| backend/packages/Upgrade/src/api/models/DecisionPoint.ts | Added index on experiment foreign key to optimize JOIN performance |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…feature/2859-optimize-experiment-pagination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me if there's really no need for that joined data in the frontend.
However, the indexes that were added to the typeorm models are to not added to the database until a migration is created and run. Since there's no migration file in this pr, the indexes were probably not added. Maybe they're not necessary if we're already seeing the performance improvements without them.
|
I will open another PR later that merges into Feel free to leave comments in the issue #2859, if anyone has any suggestions. |
Resolves #2859
FYI, I asked Copilot for input while investigating this issue, and it suggested removing database JOINs that aren’t required for the experiment root table. Applying this change significantly improved performance in my testing. Since I’m less familiar with this area of the codebase, I’d appreciate a careful review to confirm the changes are safe and correct.
Problem
The
/api/experiments/paginatedendpoint was experiencing severe performance degradation:Root cause: The
findPaginatedmethod was performing 20 LEFT JOINs to eagerly load deeply nested relationships that were not required for the experiment list table display.Solution
1. Query Optimization (ExperimentService.ts)
Reduced database JOINs from 20 to 3 by loading only essential data for table rendering:
Removed unnecessary JOINs:
queries,factors,levels,metric- not displayed in tableexperimentSegmentInclusion/Exclusionwith nested segments - only needed in detail viewlevelCombinationElements,level- factorial experiment detailsconditionPayloads- runtime assignment dataRetained required JOINs:
conditions- basic experiment structurepartitions- needed for app context display and search functionalitystratificationFactor- needed for post-experiment rule displayAdditional improvements:
formattingConditionPayload,formattingPayload,reducedConditionPayload,inferListTypesForExperimentListForExperimentRedesignDataChange)2. Database Indexing
Added strategic indexes to improve JOIN and filtering performance:
Experiment table:
idx_experiment_updated_at- optimizes default sortingidx_experiment_state- optimizes state-based filteringidx_experiment_name- optimizes name searchForeign key indexes:
idx_decision_point_experiment- optimizes partition JOINidx_experiment_condition_experiment- optimizes condition JOINPerformance Impact
Expected improvement: 7-14x faster
The paginated experiment list now loads only the minimal data required for display, with detailed information fetched separately when viewing individual experiments.
Testing
Breaking Changes
None. The API response structure remains unchanged; we simply load less nested data that was never used by the frontend table component.