Skip to content

perf(secure_tcp_socket): add std::span receive callback to remove per-read allocations#322

Merged
kcenon merged 3 commits into
mainfrom
feature/317-secure-tcp-span-callback
Dec 18, 2025
Merged

perf(secure_tcp_socket): add std::span receive callback to remove per-read allocations#322
kcenon merged 3 commits into
mainfrom
feature/317-secure-tcp-span-callback

Conversation

@kcenon

@kcenon kcenon commented Dec 18, 2025

Copy link
Copy Markdown
Owner

Summary

  • Add set_receive_callback_view(std::span<const uint8_t>) API for zero-copy TLS data reception
  • Implement lock-free callback storage using shared_ptr + atomic_load/store
  • Remove mutex from receive hot path for better performance under high TPS

Changes

  • Header (include/kcenon/network/internal/secure_tcp_socket.h):

    • Add <span> include
    • Add callback type aliases for lock-free storage
    • Add set_receive_callback_view() method with comprehensive documentation
    • Change callback members to shared_ptr for atomic access
  • Implementation (src/internal/secure_tcp_socket.cpp):

    • Implement set_receive_callback_view() with atomic store
    • Update all callback setters to use lock-free pattern
    • Modify do_read() to prefer view callback (zero-copy) over vector callback
    • Remove mutex from callback invocation hot path

Test plan

  • Build passes with -DCMAKE_BUILD_TYPE=Release
  • All existing tests pass (99% - 632/641 passed)
  • TcpSocket callback tests pass (same pattern as this implementation)

Notes

Closes #317
Part of #315

…-read allocations

- Add set_receive_callback_view() API for zero-copy span-based receive
- Implement lock-free callback access using shared_ptr + atomic operations
- Prefer view callback over vector callback when both are set
- Remove mutex from receive hot path for better performance
- Keep legacy vector callback for backward compatibility

Part of #317
Add documentation for secure_tcp_socket zero-allocation receive path
feature in both English and Korean CHANGELOGs.

Part of #317
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

Document the new set_receive_callback_view() API that provides
zero-copy TLS data reception using std::span and lock-free callback
storage for improved performance under high TPS.

Refs: #317, #315, #316
@github-actions

Copy link
Copy Markdown
Contributor

Performance Comparison

Base Branch Results

No base results

PR Branch Results

No PR results

@kcenon kcenon merged commit caa27be into main Dec 18, 2025
50 of 51 checks passed
@kcenon kcenon deleted the feature/317-secure-tcp-span-callback branch December 18, 2025 16:09
kcenon added a commit that referenced this pull request Apr 13, 2026
…-read allocations (#322)

* perf(secure_tcp_socket): add std::span receive callback to remove per-read allocations

- Add set_receive_callback_view() API for zero-copy span-based receive
- Implement lock-free callback access using shared_ptr + atomic operations
- Prefer view callback over vector callback when both are set
- Remove mutex from receive hot path for better performance
- Keep legacy vector callback for backward compatibility

Part of #317

* docs: update CHANGELOG for secure_tcp_socket span callback

Add documentation for secure_tcp_socket zero-allocation receive path
feature in both English and Korean CHANGELOGs.

Part of #317

* docs: add secure_tcp_socket zero-copy receive to changelog

Document the new set_receive_callback_view() API that provides
zero-copy TLS data reception using std::span and lock-free callback
storage for improved performance under high TPS.

Refs: #317, #315, #316
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.

perf(secure_tcp_socket): add std::span receive callback to remove per-read allocations

1 participant