Skip to content

Reduce overhead of Swift runtime initialization for YYJSONDecoder#10

Draft
mattt wants to merge 2 commits into
mainfrom
mattt/reduce-cold-start
Draft

Reduce overhead of Swift runtime initialization for YYJSONDecoder#10
mattt wants to merge 2 commits into
mainfrom
mattt/reduce-cold-start

Conversation

@mattt
Copy link
Copy Markdown
Owner

@mattt mattt commented Jan 14, 2026

This PR attempts to resolve the significant cold start delay of YYJSONDecoder compared to Foundation JSONDecoder observed by @zshannon in #9.

Throwing spaghetti at the wall to see what sticks:

  • We can reduce allocations by creating a _YYDecoderConfig class to share strategy configuration across all nested decoders and containers. This should help a lot for deeply nested JSON.
  • If nothing else, having a YYJSONDecoder.warmup(for:) method gives API consumers an explicit way to amortize those startup costs on their own terms.

Other things we can try:

  • Annotating with @inlinable + @usableFromInline to allow for cross-module inlining and avoiding witness table lookups
  • Annotating hot paths with @inline(__always) to similar effect
  • Annotating enums and structs with @frozen, which eliminates runtime metadata by fixing ABI layout at compile time

@mattt
Copy link
Copy Markdown
Owner Author

mattt commented Jan 15, 2026

@zshannon When you get a chance, please give this branch a try alongside the 0.3.0 release of Replay. I'm very curious to see if fda9de6 made things better.

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