More efficient parsing and serialization - #502
Open
plokhotnyuk wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes YAML parsing and serialization by reducing allocations and streamlining hot paths.
Changes:
- Reworks reader, tokenizer, parser, and composer internals for efficiency.
- Reuses immutable serialization events and builders.
- Updates decoder expectations for sequence-backed values.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
DecoderSuite.scala |
Accepts generic sequences in decoder test. |
TokenizerContext.scala |
Replaces indentation deque with an array stack. |
Tokenizer.scala |
Optimizes tokenization paths and allocations. |
Token.scala |
Simplifies scalar construction. |
Reader.scala |
Optimizes character traversal; introduces CR handling defects. |
ParserImpl.scala |
Reduces parser allocations and chained operations. |
Event.scala |
Uses direct event and metadata construction. |
Composer.scala |
Optimizes event composition and alias storage. |
SerializerImpl.scala |
Reuses immutable events and simplifies traversal. |
PresenterImpl.scala |
Uses direct event construction. |
Suppressed comments (2)
core/shared/src/main/scala/org/virtuslab/yaml/internal/load/reader/Reader.scala:114
- The CRLF lookahead mutates
ibefore confirming the next character is\n. Thus whitespace such as"\rvalue"silently drops thev; inspect withcharAt(i)first and only advance the extra position for a confirmed CRLF pair.
c == '\n' || c == '\r' && {
i < len && {
c = in.charAt(i)
i += 1
c == '\n'
}
core/shared/src/main/scala/org/virtuslab/yaml/internal/load/reader/Reader.scala:134
read()must return and consume the current character, but for a standalone\rfollowed by text this probe overwritesc, advances twice, and returns the next character. Only consume and return\nwhen a CRLF pair is actually present.
c == '\n' || c == '\r' && {
i < len && {
c = in.charAt(i)
i += 1
c == '\n'
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+84
to
+89
| c == '\n' || c == '\r' && { | ||
| i < len && { | ||
| c = in.charAt(i) | ||
| i += 1 | ||
| c == '\n' | ||
| } |
plokhotnyuk
force-pushed
the
main
branch
3 times, most recently
from
September 1, 2026 07:50
9924d9e to
b92b978
Compare
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.
Below are benchmark results using Oracle GraalVM 25 on MacBook M5
Before:
After: