Skip to content

perf(core): cache operation IDs belonging to space to avoid preflight DB lookup#673

Merged
AlessandroPomponio merged 2 commits intomainfrom
maj_cache_verified_operations
Mar 9, 2026
Merged

perf(core): cache operation IDs belonging to space to avoid preflight DB lookup#673
AlessandroPomponio merged 2 commits intomainfrom
maj_cache_verified_operations

Conversation

@michael-johnston
Copy link
Copy Markdown
Member

_perform_preflight_checks_for_sample_store_methods decorates every
sample store method (measurement_requests_for_operation,
complete_measurement_request_with_results_timeseries, etc.) and
verifies that the supplied operation_id belongs to the space before
allowing the call through. It did this by calling getResource(operation)
on every decorated call — a full DB round-trip each time.

For the common path for ado show X operation which goes through from_operation_id, this check is redundant as
the operation was already fetched to locate the space, so ownership is
proven by construction.

The fix adds _verified_operation_ids: set[str] to DiscoverySpace.init
and guards the getResource call in the preflight decorator behind a set
membership test. from_operation_id pre-populates the set with the
operation_id immediately after the space is built, so any subsequent
decorated call on that space skips the DB round-trip entirely.

The full ownership check (getResource + uri comparison) is still
executed for operation IDs not in the set, preserving correctness for
spaces constructed via other paths (e.g. from_stored_configuration
called directly) where ownership has not yet been established.

Measured saving per decorated method call: ~653ms (this is saving in ado show X operation call)

…B lookup

_perform_preflight_checks_for_sample_store_methods decorates every
sample store method (measurement_requests_for_operation,
complete_measurement_request_with_results_timeseries, etc.) and
verifies that the supplied operation_id belongs to the space before
allowing the call through. It did this by calling getResource(operation)
on every decorated call — a full DB round-trip each time.

For the common path for `ado show X operation` which goes through from_operation_id, this check is redundant as
the operation was already fetched to locate the space, so ownership is
proven by construction.

The fix adds _verified_operation_ids: set[str] to DiscoverySpace.__init__
and guards the getResource call in the preflight decorator behind a set
membership test. from_operation_id pre-populates the set with the
operation_id immediately after the space is built, so any subsequent
decorated call on that space skips the DB round-trip entirely.

The full ownership check (getResource + uri comparison) is still
executed for operation IDs not in the set, preserving correctness for
spaces constructed via other paths (e.g. from_stored_configuration
called directly) where ownership has not yet been established.

Measured saving per decorated method call: ~653ms (this is saving in ado show X operation call)
@AlessandroPomponio AlessandroPomponio changed the title fix(perf): cache verified operation IDs to skip redundant preflight DB lookup perf(core): cache operation IDs belonging to space to avoid preflight DB lookup Mar 9, 2026
Copy link
Copy Markdown
Member

@AlessandroPomponio AlessandroPomponio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@AlessandroPomponio AlessandroPomponio added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit fb82c5d Mar 9, 2026
19 checks passed
@AlessandroPomponio AlessandroPomponio deleted the maj_cache_verified_operations branch March 9, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants