[perf] Optimize enclave with async I/O, parallel decryption, and HashMap#259
Merged
jplock merged 4 commits intoaws-samples:mainfrom Dec 24, 2025
Merged
Conversation
- Switch from BTreeMap to HashMap for O(1) field lookups - Add rayon for parallel HPKE field decryption across multiple cores - Convert to async I/O using tokio and tokio-vsock for concurrent client handling (spawn task per connection) - Add async protocol functions (send_message_async, recv_message_async) - Pre-allocate HashMap with capacity hints to reduce allocations - Use Mutex for thread-safe error collection during parallel decryption Performance impact: - Field decryption scales with CPU cores for multi-field requests - Concurrent request handling eliminates head-of-line blocking - HashMap provides constant-time field access vs O(log n) for BTreeMap The code maintains no-panic guarantees with proper error handling throughout all new code paths.
Minimize tokio dependency surface area by removing features not used: - net: tokio-vsock provides its own vsock networking - sync: No tokio sync primitives used in the codebase Retained features: - rt-multi-thread: Required for async runtime and tokio::spawn - io-util: Required for AsyncReadExt/AsyncWriteExt traits - macros: Required for #[tokio::main]
Reverts the async/tokio approach in favor of simpler synchronous code: - Removes tokio and tokio-vsock dependencies - Uses std::thread for concurrent client handling - Keeps rayon for parallel field decryption - Keeps HashMap for O(1) lookups - Reduces external dependency surface area The enclave typically handles a single parent connection at a time, making async overhead unnecessary. Rayon still provides parallelization for CPU-bound field decryption operations.
Critical fixes: - Add connection limiting (MAX_CONCURRENT_CONNECTIONS=32) to prevent DoS - Create SecureHpkePrivateKey wrapper with ZeroizeOnDrop for key material - Remove expect() calls in functions.rs, use proper error handling High severity fixes: - Fix mutex poisoning: log critical error instead of silently ignoring - Sanitize error messages in logs to prevent sensitive data leakage - Gate detailed error logging behind debug builds only The enclave now: - Limits concurrent connections to prevent resource exhaustion - Properly zeroizes HPKE private key material on drop - Never panics in production code paths - Logs critical conditions (mutex poisoning) for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance impact:
The code maintains no-panic guarantees with proper error handling throughout all new code paths.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.