Skip to content

Hoist the loop-invariant ontology-URI lookup out of the label predicate#17

Merged
namedgraph merged 1 commit into
masterfrom
perf/vocab-label-hoist
Jul 13, 2026
Merged

Hoist the loop-invariant ontology-URI lookup out of the label predicate#17
namedgraph merged 1 commit into
masterfrom
perf/vocab-label-hoist

Conversation

@namedgraph

Copy link
Copy Markdown
Member

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.5s main execution) — specifically building the vocabulary dropdowns from dcterms.rdf.

The culprit is the predicate in local:ontology-label:

$vocab/rdf:RDF/*[@rdf:about = local:ontology-uri($vocab)]

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)

before after
init-overlay 1428 ms ~20 ms
toolbar visible after navigation 2085 ms 729 ms

The remaining gap to first paint is the window.onload wait on external fonts, not the editor.

Verification

  • Annotation dropdowns populate identically (FOAF: 62 properties / 13 classes, DCMI: 55 / 22) with ontology labels resolving through the changed path
  • Headless suites: 47/47 pass

🤖 Generated with Claude Code

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>
@namedgraph namedgraph merged commit 78fed09 into master Jul 13, 2026
2 checks passed
@namedgraph namedgraph deleted the perf/vocab-label-hoist branch July 13, 2026 20:10
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.

1 participant