Hoist the loop-invariant ontology-URI lookup out of the label predicate#17
Merged
Conversation
SaxonJS does not hoist local:ontology-uri($vocab) out of the predicate in local:ontology-label, so the whole vocabulary document was rescanned once per description element - quadratic on the striped, 1400-description dcterms.rdf and ~1.4s of every editor boot spent in init-overlay. Binding the URI to a variable first makes the scan linear: init-overlay drops from ~1430ms to ~20ms, and the toolbar appears at ~0.7s instead of ~2.1s after navigation (measured headless on localhost). 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.
Problem
The editor toolbar appeared ~1.7s after the page content. Profiling the boot headless showed the whole gap was
init-overlay(1428 ms of the ~1.5smainexecution) — specifically building the vocabulary dropdowns from dcterms.rdf.The culprit is the predicate in
local:ontology-label:SaxonJS does not hoist the loop-invariant
local:ontology-uri($vocab)call out of the predicate, so the whole vocabulary document is rescanned once per description element — quadratic on the striped, 1400-description dcterms.rdf (foaf's 94 descriptions cost ~20 ms; dcterms' 1400 cost ~1350 ms).Fix
Bind the ontology URI to a variable before the predicate (one-line hoist, same semantics — including the empty-URI case, where the predicate is false everywhere as before).
Measured impact (headless, localhost)
init-overlayThe remaining gap to first paint is the
window.onloadwait on external fonts, not the editor.Verification
🤖 Generated with Claude Code