Skip to content

perf(schema-org): reduce entry normalization - #815

Merged
harlan-zw merged 3 commits into
mainfrom
perf/schema-org-entry-cache
Jun 30, 2026
Merged

harlan-zw merged 3 commits into
mainfrom
perf/schema-org-entry-cache

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

None.

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Schema.org no longer forces every cached head entry to normalize again during entries:resolve. Cached tags are reused unless the entry owns schema.org nodes, and script sorting avoids coercing missing type values into strings.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Schema.org metadata so structured data is collected more reliably and duplicated entries are avoided.
    • Refined script tag sorting behavior to better preserve correct ordering for different script types.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@harlan-zw, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39ce3c7d-b058-4739-b442-e9aad42e72e2

📥 Commits

Reviewing files that changed from the base of the PR and between 0dc05dc and b8c5790.

📒 Files selected for processing (2)
  • bench/perf-ci.mjs
  • packages/schema-org/src/plugin.ts
📝 Walkthrough

Walkthrough

The schema-org unhead plugin is refactored to centralize tag detection via a new isSchemaOrgTag helper and a collectTag function used across entries:resolve and entries:normalize. The tags:afterResolve hook gains lazy toRemove set allocation. In sort.ts, script tag type derivation replaces String() coercion with a typeof string guard.

Changes

Schema-org plugin refactor

Layer / File(s) Summary
isSchemaOrgTag helper and HeadTag import
packages/schema-org/src/plugin.ts
Adds HeadTag import and isSchemaOrgTag(tag) function to centralize identification of schema-org JSON-LD script tags and the schema-org-graph key.
collectTag, entries:resolve, and entries:normalize rewiring
packages/schema-org/src/plugin.ts
Adds collectTag function; entries:resolve resets graph state each cycle and scans _tags, deleting them when schema-org tags are present; entries:normalize delegates to collectTag instead of inline parsing.
Lazy toRemove in tags:afterResolve
packages/schema-org/src/plugin.ts
Refactors tags:afterResolve to skip entries without props early and only allocate the toRemove set and filter ctx.tags when schema-org tags are actually encountered.

Script type coercion fix

Layer / File(s) Summary
Script type string guard in capoTagWeight
packages/unhead/src/server/sort.ts
Replaces String(tag.props.type) with typeof tag.props.type === 'string' ? tag.props.type : '' to avoid unintended coercion of non-string values affecting weight decisions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • unjs/unhead#734: Modifies the same capoTagWeight script branch in sort.ts, adding special-case weights for importmap and speculationrules types that interact with the type derivation being changed here.
  • unjs/unhead#785: Modifies packages/schema-org/src/plugin.ts in the same tags:resolve hook area affected by this refactor.

Poem

🐇 Hop hop, the graph resets with care,
collectTag leaps through the tags with flair,
No coercion tricks for script type strings,
Lazy sets bloom — what efficiency brings!
A tidy warren, neat and bright,
Schema-org nodes all ordered right. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main performance-focused schema.org normalization change.
Description check ✅ Passed The description follows the template and explains the enhancement, linked issue, and change summary.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/schema-org-entry-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle Size

⚠️ 1 bundle grew · net +46 B gz

Bundle Gzipped Δ
Schema.org (Minimal) 9.5 kB → 9.5 kB 🔴 +46 B (+0.5%)
All bundles (12)
Bundle Gzipped Raw
Core
Client (Minimal) 5.1 kB 12.7 kB ✅
Client (Full) 8.5 kB 22 kB ✅
Server (Minimal) 4.5 kB 11.2 kB ✅
Vue
Vue Client (Minimal) 5.6 kB 13.8 kB ✅
Vue Client (Full) 9.3 kB 24 kB ✅
Vue Server (Minimal) 5 kB 12.2 kB ✅
React
React Client (Minimal) 5.5 kB 13.8 kB ✅
React Client (Full) 9.4 kB 24.4 kB ✅
React Server (Minimal) 4.8 kB 11.9 kB ✅
Schema.org
Schema.org (Minimal) 9.5 kB 26.3 kB 🔴
Schema.org Imports 0.1 kB 0.1 kB ✅
Schema.org Vue Meta 0.4 kB 0.8 kB ✅

⚡ Performance (directional)

🟢 2 faster

Benchmark base → PR Δ
Schema.org cached render (CPU) 0.654 ms → 0.376 ms 🟢 -42.5%
Schema.org cached allocated / render 220.7 KiB → 145.3 KiB 🟢 -75.4 KiB (-34.2%)
All benchmarks (9)
Benchmark PR Δ RME
SSR render (CPU) 0.435 ms ~ noise ±10.9%
SSR render (wall) 0.268 ms ~ noise ±6.0%
SSR allocated / render 272.9 KiB ~ noise —
Schema.org cached render (CPU) 0.376 ms 🟢 -42.5% ±5.6%
Schema.org cached render (wall) 0.250 ms ℹ️ -37.2% ±2.2%
Schema.org cached allocated / render 145.3 KiB 🟢 -75.4 KiB (-34.2%) —
CSR DOM mutations / nav 38 ~ noise —
CSR re-render (CPU) 0.840 ms ~ noise ±4.8%
CSR re-render (wall) 0.484 ms ~ noise ±2.0%

Baseline: main @ fb6dce2 · 2026-06-30 · gzipped is the headline size metric · perf is directional (shared-runner, gated)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/schema-org/src/plugin.ts`:
- Around line 103-107: Reset the closure-scoped resolvedMeta on each
'entries:resolve' cycle in plugin.ts so removed metadata does not leak into
later resolveGraph() runs. Update the 'entries:resolve' handler alongside the
existing graph reset to reinitialize resolvedMeta each cycle, and keep the merge
logic in resolveGraph() using the fresh per-cycle state for title, description,
canonical URL, image, and templateParams.schemaOrg.
- Line 66: The tag position assignment in plugin.ts is incorrectly overriding an
explicit tag.tagPosition value because of operator precedence. Update the logic
around the tagPosition handling so TagConfig preserves an existing
tag.tagPosition value and only falls back to config.tagPosition when it is
unset, using the relevant setup in the plugin() path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffc7937c-22c0-4c73-b572-b9a29da85211

📥 Commits

Reviewing files that changed from the base of the PR and between fb6dce2 and 0dc05dc.

📒 Files selected for processing (2)
  • packages/schema-org/src/plugin.ts
  • packages/unhead/src/server/sort.ts

Comment thread packages/schema-org/src/plugin.ts Resolved
Comment thread packages/schema-org/src/plugin.ts Resolved
@harlan-zw
harlan-zw merged commit aa9c75c into main Jun 30, 2026
7 checks passed
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