perf(epp): derive Scope allowed-key sets once at datalayer init - #2471
Conversation
| // the process lifetime, so entries are never evicted. | ||
| var scopeSpecs sync.Map // fwkplugin.Plugin -> *scopeSpec | ||
|
|
||
| func scopeSpecFor(plugin fwkplugin.Plugin) *scopeSpec { |
There was a problem hiding this comment.
This is an init logic, I recommend to call this explicitly from the datalayer init code instead of doing it on the fly
There was a problem hiding this comment.
Done. The sets are now derived once at startup: the runner calls datalayer.RegisterScopeSpecs(handle.GetAllPlugins()) next to ValidateAndOrderDataDependencies, after auto-created producers exist, and Scope looks the spec up by the plugin's typed name (the same key ValidateAndOrderDataDependencies uses).
A plugin that never went through registration is confined to nothing, with a one-time error log, so a wiring bug fails closed instead of silently widening access. This also drops the lazy sync.Map and the plugin-as-map-key requirement.
There was a problem hiding this comment.
updated bench data in PR description too
Scope rebuilt the allowedPut/allowedGet maps from Produces()/Consumes() on every invocation, though the declarations are fixed at plugin construction and Scope runs for every filter, scorer, and DataProducer on every request. Derive the sets once per plugin instance and share them read-only across invocations. BenchmarkScope: -45% time / -40% allocs at 10 endpoints, -6% / -50% at 100. Confinement behavior is unchanged. Signed-off-by: Luke Van Drie <lukevandrie@google.com>
Scope looks up a spec registered by RegisterScopeSpecs, keyed by the plugin's typed name, instead of caching lazily by plugin identity. The runner registers every plugin once the full set, including auto-created producers, is known. An unregistered plugin is confined to nothing and the miss is logged once per typed name. Signed-off-by: Luke Van Drie <lukevandrie@google.com>
8697fa9 to
2b0b4ae
Compare
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
datalayer.Scoperebuilt theallowedPut/allowedGetmaps fromProduces()/Consumes()on every invocation. Scope runs for every filter, every scorer, and every DataProducer on every request, while the declarations are fixed at plugin construction.The sets are now derived once at startup: the runner calls
datalayer.RegisterScopeSpecs(handle.GetAllPlugins())next toValidateAndOrderDataDependencies, after auto-created producers exist.Scopelooks the spec up by the plugin's typed name, the same keyValidateAndOrderDataDependenciesuses. A plugin that never went through registration is confined to nothing, with a one-time error log, so a wiring bug fails closed.Benchmarks (
benchstat, 10 interleaved runs per side, Apple M4 Pro):Which issue(s) this PR fixes:
Part of #2470
Release note (write
NONEif no user-facing change):Test plan
./pkg/epp/datalayer/...,./pkg/epp/scheduling/...,./pkg/epp/requestcontrol/..., disagg profile-handler, and./cmd/epp/...unit tests (tests that assert scoped data flow now register their plugins)make presubmitstages (signed-commits-check trips on the pre-existing GitHub merge commit843d2271, which the DCO and signed-commit CI checks exempt)BenchmarkScopebefore/after with benchstat