Skip to content

Conversation

@bmartel
Copy link
Contributor

@bmartel bmartel commented Nov 7, 2025

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.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for label-studio-storybook canceled.

Name Link
🔨 Latest commit a225da7
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/690e52f64b77fa00083a9d35

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit a225da7
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-docs-new-theme/deploys/690e52f6c67cbd0008bda68b

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit a225da7
🔍 Latest deploy log https://app.netlify.com/projects/heartex-docs/deploys/690e52f6b8700d00088a6da2

@github-actions github-actions bot added the fix label Nov 7, 2025
@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for label-studio-playground canceled.

Name Link
🔨 Latest commit a225da7
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/690e52f63fe89a0007095837

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

❌ 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.

Files with missing lines Patch % Lines
label_studio/core/current_request.py 85.71% 2 Missing ⚠️
label_studio/fsm/models.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #8787       +/-   ##
============================================
+ Coverage    67.28%   80.69%   +13.40%     
============================================
  Files          804      251      -553     
  Lines        62366    22990    -39376     
  Branches     10419        0    -10419     
============================================
- Hits         41964    18552    -23412     
+ Misses       20399     4438    -15961     
+ Partials         3        0        -3     
Flag Coverage Δ
lsf-e2e ?
lsf-integration ?
lsf-unit ?
pytests 80.69% <87.87%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bmartel bmartel merged commit 0b92945 into develop Nov 7, 2025
53 checks passed
@robot-ci-heartex robot-ci-heartex deleted the fb-fit-671-fixes branch November 7, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants