perf: avoid buffering stream when computing placeholder PNG C2PA chunk#2154
Conversation
Merging this PR will improve performance by 11.96%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
Merging this PR will improve performance by 12.06%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | small |
25.2 ms | 22.5 ms | +12.06% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ok-nick/png-mem-opt (48f1ae2) with main (350e138)
Footnotes
-
64 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
gpeacock
left a comment
There was a problem hiding this comment.
I'm wondering if there are side effects caused by modifying the input stream. We probably don't expect that. It is mut so that we can seek, not modify.
|
@gpeacock I'm not sure what you mean. The input stream is read-only and this change only seeks? |
|
Discussed offline with Gavin. |
Reduces memory usage when reading/signing a PNG that doesn't contain a C2PA manifest by optimizing
get_object_locations_from_streamto quickly find where the C2PA chunk goes rather than computing it viawrite_cai. When signing a 100MB PNG, the total memory usage decreases by 29.4%.Before:


After: