perf(schema-org): rework graph resolution#616
Merged
harlan-zw merged 10 commits intoDec 17, 2025
Conversation
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.
β¦lementation-011CV2NuQ4u4zUBsbSGKSENb
- 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).
β¦implementation-011CV2NuQ4u4zUBsbSGKSENb
β¦implementation-011CV2NuQ4u4zUBsbSGKSENb
Contributor
Bundle Size Analysis
|
Closed
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.
π Linked issue
β Type of change
π Description
Rework schema.org so tree shaking works, improved bundle size and more efficient javascript.
hashutils for an auto-incrementing count for the ids. Please test your schema.org implementation in rich results after updating.β Comparison Results
Bundle Size
Benchmarks (ops/sec, higher = better)
Summary: ~8.3kB smaller bundle (gzip: -2.2kB), core operations 15-135% faster.