Skip to content

Conversation

@meetrick
Copy link

Summary

Trim leading whitespace from decoded JSON-RPC messages in StreamCodec, resolving a TODO and improving IPC message handling.

Problem

When StreamCodec::decode() parses JSON-RPC messages over IPC, it includes leading whitespace (newlines, tabs, spaces) that appears between messages. This is unnecessary since:

  1. Leading whitespace is not part of the JSON message
  2. It wastes memory storing meaningless bytes
  3. It clutters debug logs with extra whitespace
  4. The start_idx variable already tracks where JSON actually begins, but was not being used to discard prior bytes

Before

Input:  "{ msg: 1 }\n\n\n\n{ msg: 2 }"
Output: "\n\n\n\n{ msg: 2 }"  // includes leading whitespace

After

Input:  "{ msg: 1 }\n\n\n\n{ msg: 2 }"
Output: "{ msg: 2 }"  // clean JSON only

User Benefits

  • Cleaner logs: Debug output shows clean JSON without leading garbage
  • Memory efficiency: No allocation for unnecessary whitespace bytes
  • Predictable output: Messages always start with { or [

Changes

  • stream_codec.rs: Discard bytes before start_idx in decode()
  • Updated whitespace test expectations
  • Updated huge test to start with { directly
  • Removed TODO comment

Remove leading whitespace before JSON start in IPC message decoding.
This improves memory efficiency and log readability.

Signed-off-by: Hwangjae Lee <[email protected]>
Signed-off-by: Hwangjae Lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant