Repository navigation
Description
Part of #722, planned for 10.0.0. Follow-up to the accepted SMTP SIZE implementation in #748 and the content-negotiation work in #742.
Completed and accepted for 10.0.0 (unreleased). The audit led to internal content-inspection and provider-discovery optimizations. Keep the current SIZE behavior and all content/security checks: no opt-in, opt-out, automatic threshold or further fine-tuning is justified by a known application workload now. The implementation and reproducible evidence are committed and pushed on codex/10.0.0.
The dated audit checkpoints below retain the investigation's intermediate findings; the final decision supersedes their earlier proposals.
Why
The send path now performs more inspection and accounting before submitting an email. SIZE measurement adds a serialization pass; content negotiation, optional local size limits and message protection can introduce other reads or processing. For batches of thousands of emails, we need to know where CPU time and elapsed delays actually go, rather than assume that these checks are cheap or that SMTP latency hides them.
The goal is to quantify the cost and remove avoidable work. A new API is a possible outcome, not a foregone conclusion.
Investigation
- Build a repeatable synthetic workload against local SMTP fixtures, with warm-up, repeated runs, comparable payloads and reused connections. No live email or external delivery.
- Attribute CPU time and elapsed delays separately: SIZE measurement, encoding/content inspection, normal MIME serialization, configured local-size validation, optional message protection, queue/pool waits and SMTP I/O. Include allocation/GC effects and identify fixture overhead.
- Exercise batches of a few thousand small messages, attachment-heavy messages and exact/protected content. Compare sequential shared-connection sends with bounded pooled concurrency, and in-memory with file-backed content. Include SIZE-advertising and non-advertising servers.
- Compare the current implementation with controlled experimental variants that isolate SIZE and content-negotiation costs independently. Temporary measurement variants must not become public behavior or silently change the production implementation.
- Report milliseconds per message, latency distributions, batch throughput and the runtime/workload details. Keep CPU consumption distinct from waiting time and synthetic results distinct from production promises.
Decision after measurement
First look for redundant content passes, repeat work and avoidable allocations that can be removed without changing behavior. Reuse must respect the actual transmitted representation, including provider conversion, exact/protected content and the selected connection.
If significant costs remain, compare keeping automatic behavior with opt-out or opt-in controls. For each candidate, show the measured savings, which checks or facts become unavailable, and the resulting caller responsibilities. Decide whether SIZE and encoding inspection need independent controls or whether no new API is justified. Do not preselect a broad performance-mode switch or silently relax TLS/security requirements; disabling preflight inspection is not the same as disabling normal MIME encoding.
Any proposed public API needs maintainer design approval and the API expansion workflow, including property, Spring, CLI and diagnostic support where appropriate, plus documentation of changed defaults or semantics.
Initial audit — 28 September 2026
This records the initial, pre-optimization measurements. At that point no production behavior or public API had changed; the completed internal-optimization follow-up is recorded below. The harness, reports and raw results are now retained under 03_SMTP_ROBUSTNESS_IMPROVEMENT_PLAN/performance-audit and tools/performance.
The main comparison used 12 loopback scenarios, three independent JVMs per variant, and two measured batches per scenario: 156,960 measured sends. Small batches contain 2,000 messages; attachment/exact/signed batches contain 60 messages with 256 KiB attachments. Environment: Windows 11, i7-11700K, JDK 21+35, Jakarta Mail API 2.1.5 and Angus 2.0.5. These are developer-workstation results, not production throughput promises.
Median elapsed milliseconds per sequential email (not CPU milliseconds):
| Workload | Current | Omit SIZE | Omit content inspection |
|---|---|---|---|
| Small composed email | 3.83 | 3.15 | 3.83 |
| Memory attachment | 13.80 | 11.87 | 14.04 |
| Exact EML | 16.93 | 17.00 | 8.45 |
| DKIM-signed email | 29.20 | 28.59 | 20.98 |
The important next step is an internal optimization, not a broad opt-out. JFR identifies the byte-by-byte exact/protected-body scan as a hotspot. A separate matched experiment kept the checks but read buffers: exact EML improved from 17.18 to 11.35 ms, and DKIM from 28.93 to 22.98 ms. This is an isolated prototype; it still needs production boundary regressions and small-body allocation cleanup.
SIZE is different: it repeats MIME output and adds one full attachment read for composed content. With a 256 KiB attachment, reads fell from 528,384 to 266,240 bytes when SIZE was omitted. Continuous component measurements put exact-content SIZE counting near 0.24 ms, versus 2.16 ms for composed attachment MIME output/counting. Repeated Jakarta StreamProvider discovery also appears in allocation stacks; investigate a packaged application classpath before choosing a remedy.
Recommendation: optimize the existing scan first, retain safeguards, then remeasure SIZE independently. A SIZE opt-out would lose local oversize preflight, automatic declaration and the measured-size receipt fact; a broad content-inspection bypass loses substantially more validation. Neither has been selected. Windows CPU counter granularity, fixture work, queueing and allocation-sampling limits are documented in the report.
Internal optimization and repeat audit — 28 September 2026
This checkpoint records the approved internal content-inspection optimization, which has since been accepted and committed. AngusContentNegotiation now inspects its private serialization buffer directly and reads ordinary unencoded bodies in blocks. This removes a whole-message copy and the per-byte stream-call hotspot without removing validation or changing exact/protected bytes. No public API, configuration switch or provider-selection policy has been added.
Fresh comparisons cover 141,120 measured sends in 504 batches, plus isolated components and separate profiles. The packaged runtime uses production dependencies plus the local SMTP fixture, without JUnit/Mockito/Surefire. Reference and optimized inspection classes use matched compiler settings and equally packaged overlays. Three JVMs and two measured batches per scenario/variant; 1,000 small emails or 40 large emails per batch, with 256 KiB attachments. These remain workstation loopback results, not delivery or production-capacity promises.
Median elapsed batch milliseconds per email, not CPU time or individual async latency:
| Packaged-runtime workload | Before | Optimized |
|---|---|---|
| Small composed, sequential | 1.817 | 1.701 |
| Memory attachment, sequential | 9.204 | 9.212 |
| Exact EML, sequential | 14.878 | 9.000 |
| DKIM-signed, sequential | 23.805 | 17.929 |
| Exact EML, pooled | 2.206 | 1.531 |
Exact and DKIM sequential elapsed time improved by 39.5% and 24.7% respectively. Ordinary composed mail is essentially unchanged or within overlapping ranges. Isolated exact inspection fell from 6.110 to 0.329 ms; exact-send allocation fell by roughly one 351 KiB serialized-message copy. The fixture still contributes substantial CPU, so whole-send timings are not library CPU costs.
SIZE remains independent. Omitting it experimentally saved about 0.815 ms for the memory-attachment batch and removed one full 256 KiB attachment read. Exact/signed elapsed savings were small or within variation. Repeated Jakarta StreamProvider discovery remains visible on the packaged runtime too; a separate child-JVM diagnostic selection reduced small-mail time from 1.701 to 1.053 ms, but this is not a proposed automatic JVM-wide provider setting.
Recommendation after the repeat audit:
- Keep the internal optimization and all content/security checks. Do not add a broad inspection bypass.
- Consider only a separately designed advanced SIZE-only opt-out, defaulting to the current enabled behavior. Its strongest case is avoiding an extra read of expensive attachment sources. It would lose advertised-limit preflight, automatic SIZE declaration and measured receipt facts; normal server rejection, content/security checks and independent application limits remain.
- Investigate provider discovery separately with provider/classloader ownership intact. Some of that work belongs to Jakarta Mail.
Seventeen new inspection tests cover block/line boundaries, malformed input, stream ownership and byte preservation. The full JDK 21 non-live reactor passed: 1,689 tests, zero failures/errors, one skipped. Java 11 focused verification also passed. The local report records the earlier Java 11 test timeout, its fixture fix, Windows packaging-lock retries, measurement caveats and reproduction commands.
Report: 03_SMTP_ROBUSTNESS_IMPROVEMENT_PLAN/performance-audit/inspection-optimization-results.md; raw summarized evidence remains beside the original audit results. The later discovery follow-up and final decision below complete this investigation.
Provider-discovery follow-up and final decision — 28 September 2026
Provider factory metadata is now cached per application class loader for send, lifecycle and probe adapters. Each operation still constructs fresh adapters and matches the actual provider/transport. Replacing the application loader starts a new discovery scope; send state and abort actions are never cached. Redundant MIME availability lookups were also removed without pinning a provider or changing Session ownership. Jakarta Mail's own remaining static MIME lookups stay upstream.
The maintainer accepted both optimizations and decided against adding any performance-control API. Keep all existing SIZE measurement/declaration/preflight behavior and receipt facts, including the current behavior for non-advertising servers. The synthetic evidence establishes a baseline, not a real-world need for fine-tuning or a production-throughput promise.
The final report and reproduction details are retained with the raw evidence; the harness lives in tools/performance. The shared send-architecture overview remains accurate: inspection stays attempt-local and discovery initialization is outside adapter calls, with no change to send ownership, transport lifecycle or outcome ordering.
Acceptance criteria
- Reproducible synthetic harness and recorded baseline/variant results.
- CPU, allocation and delay attribution identifies the material costs and their dependence on payload and concurrency.
- Safe internal optimizations are evaluated before exposing configuration switches.
- Evidence-backed recommendation: no API, opt-in or opt-out, with justified granularity and explicit lost guarantees.
- Final API decision accepted: no new opt-in/opt-out control or further fine-tuning; retain current SIZE behavior.
#748 can remain closed: its correctness work is complete. This is separate from #747's conformance/fault-injection suite. PIPELINING/CHUNKING stay parked under #699. The initial and repeat performance results are recorded above, both internal optimizations are accepted, and the public API decision is complete. #747 is the only remaining child of #722.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(smtp): streamline content inspection without dropping checks (#749)
perf(provider): cache loader-scoped mail adapter discovery (#749)
test(performance): add reproducible loopback mail-send audit (#749)
docs(performance): record audit results and retain SIZE behavior (#749)
bbottema commentedon Sep 28, 2026
Implemented and pushed to
codex/10.0.0for 10.0.0. Content inspection avoids redundant copying and per-byte stream overhead, and provider discovery is reused per application class loader without sharing adapters between sends.All content/security checks and existing SIZE behavior remain unchanged. No performance-control API or further fine-tuning is being added without a concrete workload to justify it. No application changes are needed.
The audit results and reproduction details are retained as a baseline. This completes the performance follow-up under #722; #747 remains the final conformance/fault-injection step.