perf: Pre-expand the Override type and avoid Object.entries in the override scan (~1.9x)#2
Draft
jeswr wants to merge 1 commit into
Draft
perf: Pre-expand the Override type and avoid Object.entries in the override scan (~1.9x)#2jeswr wants to merge 1 commit into
jeswr wants to merge 1 commit into
Conversation
…erride scan
ConfigPreprocessorOverride.findOverrideTargets() scans every resource in
the shared RdfObjectLoader (15,814 resources during a Community Solid
Server default-config boot) to find oo:Override resources. Two avoidable
costs per boot:
1. `resource.isA(IRIS_OO.Override)` is called with a *string*, so
Resource#isA re-runs term expansion for every resource in the loader.
IRIS_OO.Override is a constant absolute IRI, so it can be converted
to a term once, outside the loop.
2. `Object.entries(...)` materializes a [ key, value ] pair array per
resource purely for iteration; `Object.keys(...)` + index lookup
avoids that allocation.
Behaviour is unchanged: `isA(term)` is exactly what `isA(string)` does
after expanding the string, and iteration order and results are
identical.
Isolated A/B on the real CSS boot object graph (15,814 resources, warm,
median of 40 reps, 2-core shared box, this branch's build):
original (Object.entries + isA(string)) : 23.6 ms (min 20.4)
pre-expanded term + Object.keys : 12.4 ms (min 11.6) ~1.9x
The optimized scan returns the identical (empty) override set for the
default config, and the full test suite (including all override tests)
is unchanged and green. Small in absolute terms, but it is the single
biggest componentsjs-owned CPU frame in the instantiate phase and is
pure waste for the common zero-override configuration.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Micro-optimization of the override scan that runs before every instantiation:
ConfigPreprocessorOverride.findOverrideTargets()iterates every resource in the sharedRdfObjectLoader— 15,814 resources during a Community Solid Server default-config boot — to findoo:Overrideresources.Two avoidable per-resource costs:
resource.isA(IRIS_OO.Override)was called with a string, soResource#isAre-ran term expansion for every resource in the loader.IRIS_OO.Overrideis a constant absolute IRI: it is now converted to a term once, outside the loop.Object.entries(...)materialized a[ key, value ]pair array per resource purely for iteration;Object.keys(...)+ index lookup avoids that allocation.Behaviour
Unchanged:
isA(term)is exactly whatisA(string)does after expanding the string; iteration order and the returned override set are identical (verified on the real boot graph: identical, empty, override set for the zero-override default config). Full suite green, 100 % coverage retained.Measurements
Isolated A/B on the real CSS boot object graph (15,814 resources / 38k quads, warm, median of 40 reps,
pss-solid-test2-core shared boxnice -n 18, both arms in the same run, this branch's build):Object.entries+isA(string))Object.keys~1.9× on the scan (−11 ms per boot). The same A/B on the componentsjs 5.5.1 stack measured 24.9 → 12.6 ms. Honest framing: this is a small absolute win (the whole true-instantiate slice of a CSS boot is ~330 ms), but it was the single biggest componentsjs-owned CPU frame in the instantiate-phase profile, and it is pure waste for the common zero-override configuration.
Generated by an agent (Claude Fable 5) on @jeswr's behalf — staged on the fork for his review before upstreaming.
Review timing: This draft was prepared with Claude; I (@jeswr) will personally review it before it progresses. I'm currently batching a lot of work in flight, so expect active review Wednesday–Friday (8–10 July).