Skip to content

feat: wire performance improvements#176

Draft
jaronoff97 wants to merge 5 commits into
Arwalk:masterfrom
jaronoff97:json-bytes-hex-and-wire-perf
Draft

feat: wire performance improvements#176
jaronoff97 wants to merge 5 commits into
Arwalk:masterfrom
jaronoff97:json-bytes-hex-and-wire-perf

Conversation

@jaronoff97

Copy link
Copy Markdown

No description provided.

json: add Options.bytes_as_hex to encode/decode bytes fields as lowercase
hex strings instead of base64 (OpenTelemetry traceId/spanId format). encode
threads it via Options; decode reads a thread-local (tl_bytes_as_hex) since
std.json can't carry custom options through its recursion.

wire: decode fixed-size scalars via readInt, and pre-allocate capacity for
packed repeated scalars/enums/submessages to cut reallocations.
Comment thread src/json.zig
///
/// protobuf.json.tl_bytes_as_hex = true;
/// defer protobuf.json.tl_bytes_as_hex = false;
pub threadlocal var tl_bytes_as_hex: bool = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: while you are still at it, please do not include thread locals or globals. prefer passing arguments

@menduz menduz Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, wkt.any already does. I've created an issue

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sorry, i want to get rid of this entirely, I do this because Otel protos have some funky stuff around hex as bytes. I'm working through in this very moment if i can get rid of threadlocal and this option as I really dislike it haha

@menduz menduz Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can, changing the datatype of the field from bytes to protobufs WKT bytes google.protobuf.BytesValue, the primitive will still be bytes but its serialization will be hex, for free. you would only need to hand tune the .proto and re-emit the code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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