Repository navigation
fix(data): replace Formatter-based hex conversion that OOM-crashed (COLUMBA-EE) - #1208
Conversation
…OLUMBA-EE) "%02x".format(it) builds a java.util.Formatter per byte; measured ~37 MB of garbage for a 128 KiB hex string. On a heap already below 1% free after GC, the next 24-byte allocation in this path threw OOM and killed the process (Sentry COLUMBA-EE, AnnounceRepository.saveAnnounce hot path). Switch to a CharArray + hex-digit lookup (~3x output size) and drop the boxed take(16) list in computeIdentityHash. Regression tests bound toHexString allocation to <8x output via ThreadMXBean.getThreadAllocatedBytes: ~37 MB allocated before, ~0.4 MB after, budget 1 MiB. Fixes COLUMBA-EE
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryReplaces per-byte Formatter calls with a lookup table and a character array in both
Reviews (1) · Last reviewed commit: "fix(data): replace Formatter-based hex c..." · Reviewed by Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Diagnosis correction: the allocation-budget test reproduced excessive temporary allocation on 64 KiB inputs, not COLUMBA-EE. The crashing identity-hash conversion formats only 16 bytes. The event does not establish what occupied the 256 MiB heap. The optimization remains useful, but should be treated as an allocation mitigation, not a verified root-cause fix. PR description corrected accordingly; no merged history rewritten. |
Observed failure
Sentry COLUMBA-EE reports a fatal 24-byte allocation failure while saving an announce. ART reported a 256 MiB heap limit and less than 1% free after GC. The failure occurred in per-byte
String.formatduring hex encoding of 16 SHA-256 digest bytes. The event does not identify what occupied the heap.Allocation mitigation
hash.take(16)withhash.copyOf(16)to avoid the intermediate list.This reduces temporary allocation. It does not establish or fix the source of COLUMBA-EE's heap exhaustion.
Verification and limits
Allocation-budget tests use 64 KiB inputs, producing 128 KiB hex output. The previous implementation allocated 36.6/37.9 MB per conversion against a 1 MiB budget; the optimized implementation passed that budget. These inputs are substantially larger than the 16-byte identity-hash conversion in the event. The tests reproduce allocation inefficiency, NOT the production OOM.
The prior run reported passing HashUtils tests, the full data unit-test suite, and data ktlint. No Android heap-occupancy reproduction was performed. COLUMBA-EE's underlying cause remains unverified.