Skip to content

Conversation

@harlan-zw
Copy link
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

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.
@harlan-zw harlan-zw changed the title Claude/schema org implementation 011 cv2 nu q4u4z u bsb sgkse nb perf(schema-org): optimize graph resolution performance Nov 11, 2025
- 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.
@harlan-zw harlan-zw marked this pull request as ready for review November 13, 2025 20:11
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).
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