You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request introduces significant performance optimizations to the Finite State Management (FSM) system by minimizing unnecessary feature flag lookups and database queries, especially during read-heavy operations. The changes center around caching the FSM enabled state per request and deferring expensive field access for change detection until absolutely necessary, resulting in more efficient model loading and save operations.
FSM Feature Flag Caching and Request Context Improvements:
Added per-request caching of the FSM enabled state in CurrentContext, allowing downstream code to check a simple boolean instead of repeatedly querying feature flags. This is set once when the user is initialized and used throughout the request. [1][2]
Updated the FSM enabled check in both models and utility functions to use the cached value from CurrentContext, eliminating thousands of redundant feature flag lookups per request. [1][2]
Model Change Detection and Save Performance:
Refactored the model loading process to store raw database values on load, deferring expensive field access for change detection until a save operation actually occurs. This avoids N+1 queries for ForeignKey fields and unnecessary processing for read-only queries.
Only processes raw DB values into the change detection baseline (_original_values) when a save operation is about to run and FSM is enabled, further reducing overhead for models that are loaded but not modified. [1][2]
Serialization and Internal State Management:
Updated model serialization to exclude internal FSM tracking fields, ensuring that only necessary state is persisted and reducing memory usage.
Codebase Cleanup:
Removed unnecessary imports and streamlined feature flag checks in utility functions for better maintainability. [1][2]
These changes collectively improve request performance, especially for dashboards and bulk queries, by ensuring that expensive operations are only performed when absolutely necessary.
❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.69%. Comparing base (571ac5d) to head (a225da7). ⚠️ Report is 2 commits behind head on develop.
✅ All tests successful. No failed tests found.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant performance optimizations to the Finite State Management (FSM) system by minimizing unnecessary feature flag lookups and database queries, especially during read-heavy operations. The changes center around caching the FSM enabled state per request and deferring expensive field access for change detection until absolutely necessary, resulting in more efficient model loading and save operations.
FSM Feature Flag Caching and Request Context Improvements:
CurrentContext, allowing downstream code to check a simple boolean instead of repeatedly querying feature flags. This is set once when the user is initialized and used throughout the request. [1] [2]CurrentContext, eliminating thousands of redundant feature flag lookups per request. [1] [2]Model Change Detection and Save Performance:
_original_values) when a save operation is about to run and FSM is enabled, further reducing overhead for models that are loaded but not modified. [1] [2]Serialization and Internal State Management:
Codebase Cleanup:
These changes collectively improve request performance, especially for dashboards and bulk queries, by ensuring that expensive operations are only performed when absolutely necessary.
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]