Skip to content

Fix/performance regression#37

Merged
gitsrc merged 3 commits intomainfrom
fix/performance-regression
Jan 11, 2026
Merged

Fix/performance regression#37
gitsrc merged 3 commits intomainfrom
fix/performance-regression

Conversation

@gitsrc
Copy link
Copy Markdown
Member

@gitsrc gitsrc commented Jan 11, 2026

No description provided.

…erformance regression

In gnet v2, AsyncWrite is designed to be called from outside the event
loop (e.g., in separate goroutines) and has additional overhead. Using
AsyncWrite inside OnTraffic (an event handler) causes significant
performance degradation.

Changed all AsyncWrite calls in OnTraffic to synchronous Write calls
which are optimized for use within event handlers. This should restore
the performance to levels similar to gnet v1.0.

Performance impact: expected to restore ~76% performance loss
(v0.1.0: 2,414,510 req/s -> main: 563,386 req/s)

Signed-off-by: BlockCraftsman <167502426+BlockCraftsman@users.noreply.github.com>
Instead of calling Write() for each individual command response,
collect all responses and use Writev() for a single batch write operation.

This matches the behavior of gnet v1.0 where all responses were accumulated
in the out []byte return value and written in a single operation.

Expected to significantly improve performance by reducing system call overhead.

Performance impact:
- Reduces number of write syscalls from N to 1 per OnTraffic invocation
- Where N = number of commands in the current frame

Signed-off-by: BlockCraftsman <167502426+BlockCraftsman@users.noreply.github.com>
Reverted to the v0.1.0 approach where:
1. Use a single 'out' []byte variable that accumulates all command responses
2. Pass 'out' to each handler and receive the accumulated result back
3. Write all responses in a single Write() call at the end

This matches the exact behavior of gnet v1.0 where the React method
returned an accumulated []byte buffer that was written in one operation.

The previous Writev approach allocated separate []byte for each response,
causing unnecessary memory allocations and system call overhead.

This change should restore performance to levels comparable to v0.1.0.

Signed-off-by: BlockCraftsman <167502426+BlockCraftsman@users.noreply.github.com>
@gitsrc gitsrc merged commit daed6e0 into main Jan 11, 2026
12 checks passed
@gitsrc gitsrc deleted the fix/performance-regression branch January 11, 2026 11:27
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