dmsolr opened a new pull request, #7851:
URL: https://github.com/apache/shenyu/pull/7851
## Which issue
Refs #7836 — [Task][Performance] Remove the WebSocket payload
decode/encode/decode round trip.
## What this PR does
This delivers the deterministic, benchmark-independent part of #7836: the
acceptance item
*"Avoid full-size byte-array allocation solely for disabled diagnostics;
retain honest UTF-8
byte-size semantics if the log still says bytes."*
`ShenyuWebsocketClient.handleResult` logged
`result.getBytes(StandardCharsets.UTF_8).length`
for its INFO size diagnostic on **every** received frame. Java evaluates
arguments before
dispatching the call, so a message-sized `byte[]` was allocated on the sync
hot path even when
INFO was disabled.
Changes:
- Guard the diagnostic with `LOG.isInfoEnabled()` so nothing is computed
when INFO is off.
- Add an allocation-free `utf8ByteLength(String)` helper that walks the
string and mirrors
`getBytes(UTF_8).length` exactly, including the single-byte `?`
replacement of unpaired
surrogates. The logged value stays an honest UTF-8 byte count
(`String.length()` counts
UTF-16 code units and is **not** equivalent).
- Remove the now-unused `StandardCharsets` import.
- Add `testUtf8ByteLengthMatchesGetBytes` asserting parity with
`getBytes(UTF_8)` across ascii,
CJK, emoji, mixed, and unpaired-surrogate samples (plus the null case).
## What is intentionally deferred
The larger round-trip removal (parse the envelope once and adapt its `data`
directly to each
group's typed DTOs) and any fingerprint-representation change are **not** in
this PR:
- They alter the `DataHandler` contract shared by all 8 group handlers and
the deduplication
identity (`md5Hex(eventType + "|" + json)`), so they carry correctness
risk (numeric formatting,
field order, whitespace) that must be proven equivalent.
- The issue explicitly gates them behind before/after measurements (1k/10k+
messages, allocation,
peak heap, p99 during sync). No load benchmark has been run here, so no
performance gain is
claimed for that part.
This PR changes no sync or dedup behavior — it only removes a per-frame
allocation for a
diagnostic that is usually disabled.
## Type of change
Performance (observability-path allocation), no functional/behavioral change.
## Testing
`./mvnw test -pl shenyu-sync-data-center/shenyu-sync-data-websocket` —
`ShenyuWebsocketClientTest`
36 tests green (checkstyle clean).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]