Improve decode hot paths and collection handling#85
Open
greenm01 wants to merge 5 commits into
Open
Conversation
Author
|
Bench setup: built with Nim 2.2.6, . Ran array encoding (default) and map encoding () with 1,000,000 iterations, took median of 3 runs for the table in the PR body. Same machine/toolchain for baseline vs perf-core. |
Author
|
Bench setup: |
jangko
reviewed
Jan 27, 2026
| s.pack_array(count) | ||
| s.write(ss.data) | ||
| mixin pack_type | ||
| when compiles(val.len): |
Owner
There was a problem hiding this comment.
Please use something like this to detect if it's an array like or not:
func is_array_like[N: int, T](x: array[N, T]): bool {.compileTime.} = true
func is_array_like[T](x: seq[T]): bool {.compileTime.} = true
func is_array_like(x: auto): bool {.compileTime.} = false
when is_array_like(distinctBase(val)):
...
Owner
|
please rebase |
… payloads don’t blow the call stack and we reduce call overhead.
… now read directly as strings (no temporary JsonNode), skip_msg is iterative to avoid recursion overhead, and IntSet packing now uses its cardinality so it can write directly without buffering.
…r string/bin/ext payloads instead of allocating discard strings, and let the generic skip_msg do the same when the underlying stream supports setPosition. See src/msgpack4nim.nim. Switched sequence unpack to setLen so existing capacity can be reused. See src/msgpack4nim.nim.
…o temporary MsgStream buffer). - Lists/rings unpack by appending directly instead of staging a seq + reversing, and each element now uses a fresh ref to avoid aliasing.
…ctness while avoiding the VM recursion issue from the aborted compile‑time field count idea. The tuple paths now skip the extra count loop, and object map dispatch now covers multi‑identifier field declarations. Changes - Use tupleLen in tuple pack/unpack array branches to avoid counting fields at runtime in src/msgpack4nim.nim. - Fix unpack_field_by_name to handle a, b: T style field declarations so map‑dispatch doesn’t miss fields in src/msgpack4nim.nim. - Use a len‑fast path in pack_items_imp when val.len is available, avoiding the temporary buffer in src/msgpack4nim.nim. - Pre‑size and fill anyArray for openArray/varargs to avoid repeated add growth in src/msgpack4nim/msgpack2any.nim.
Author
|
Rebased onto latest master. |
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.
Summary
Benchmarks
Nim 2.2.6,
-d:release, 1,000,000 iters, median of 3 runs.Array encoding
Map encoding
Notes: wins are modest overall; the most consistent gains show up in map decode/skip on the larger payload.