Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(schema-org): rework graph resolution#616

Merged
harlan-zw merged 10 commits into
mainfrom
claude/schema-org-implementation-011CV2NuQ4u4zUBsbSGKSENb
Dec 17, 2025
Merged

perf(schema-org): rework graph resolution#616
harlan-zw merged 10 commits into
mainfrom
claude/schema-org-implementation-011CV2NuQ4u4zUBsbSGKSENb

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Dec 17, 2025

Copy link
Copy Markdown
Collaborator

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Rework schema.org so tree shaking works, improved bundle size and more efficient javascript.

⚠️ This drops the hash utils for an auto-incrementing count for the ids. Please test your schema.org implementation in rich results after updating.

● Comparison Results

Bundle Size

Branch Raw Gzipped Diff
main 34.1 kB 11.3 kB -
this branch 25.8 kB 9.1 kB -24% / -19%

Benchmarks (ops/sec, higher = better)

Benchmark main this branch Ξ”
simple graph 168,777 290,752 +72%
complex graph 69,506 94,400 +36%
product e-commerce 88,116 111,306 +26%
article blog 66,521 86,692 +30%
graph.find (10 nodes) 40,461 46,699 +15%
dedupe (5 duplicates) 56,481 132,912 +135%
full e2e SSR 35,476 34,790 -2% (noise)
complex e2e SSR 20,745 19,325 -7% (noise)

Summary: ~8.3kB smaller bundle (gzip: -2.2kB), core operations 15-135% faster.

claude and others added 9 commits November 11, 2025 16:26
Performance improvements:
- Added nodeIndex Map for O(1) node lookups instead of O(n) array searches
- Made resolvers tree-shakeable by replacing switch statement with const object mapping
- Optimized resolveGraph from O(nΒ²) to O(n) by building index before resolveRootNode calls
- Inlined deduplication logic to reduce separate passes through node arrays

Technical changes:
- Added nodeIndex Map to SchemaOrgGraph interface
- Modified find() method to use Map with fallback to array search during first pass
- Updated push() method to maintain nodeIndex when new nodes are added
- Converted loadResolver() from switch statement to const object mapping
- Combined deduplication and normalization passes in resolveGraph()
- Inlined helper functions (groupBy, uniqueBy, merge) into graph.ts

All existing tests pass with these optimizations.
Simplifications:
- Extracted indexNode() helper to eliminate code duplication between push() and resolveGraph()
- Simplified final normalization by replacing groupBy with inline sorting logic
- Reduced push() from 18 lines to 7 lines
- Reduced index building from 15 lines to 3 lines

The code is now more maintainable and easier to understand while maintaining the same performance characteristics.
- Replaced defu's createDefu with custom merge function
- Replaced ohash's hash with hashCode utility
- Maintains same merge behavior with deduplication
- All tests passing (477/477)
- Bundle size: 237 kB (1 kB increase from inlined merge logic)

This change aligns with the main branch removal of these dependencies while preserving all performance optimizations.
Removed ~70 lines of duplicated code by:
- Exporting groupBy, uniqueBy, and merge from util.ts
- Importing these in graph.ts instead of duplicating them
- Main chunk reduced from 4.94 kB to 2.31 kB (-2.6 kB)

Bundle remains 237 kB total but code is better organized with zero duplication.
All tests passing (477/477).
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Bundle Size Gzipped
Client (Minimal) 0.2 kB 0.2 kB
Server (Minimal) 0.3 kB 0.2 kB
Vue Client (Minimal) 0.3 kB 0.2 kB
Vue Server (Minimal) 0.3 kB 0.2 kB

@harlan-zw harlan-zw changed the title perf(schema-org): optimize graph resolution performance perf(schema-org): rework graph resolution Dec 17, 2025
@harlan-zw harlan-zw merged commit b79e46d into main Dec 17, 2025
5 checks passed
@harlan-zw harlan-zw mentioned this pull request Apr 4, 2026
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.

2 participants