Repository navigation
sdk/python: bound temporary copies in large buffered writes - #7894
jiefenghuang merged 3 commits into
Conversation
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
There was a problem hiding this comment.
Benchmarked on a 4-core / 8 GiB Linux box (Python 3.12, SQLite + local file storage, same libjfs, only juicefs.py swapped). One buffered write() of N MiB, extra peak RSS during the write:
| Size | Before | After |
|---|---|---|
| 64 MiB | 87 MiB | 25 MiB |
| 256 MiB | 289 MiB | 33 MiB |
| 512 MiB | 548 MiB | 29 MiB |
| 1 GiB | 1170 MiB | 43–129 MiB |
tracemalloc peak goes from N MiB to a constant 8 MiB. Write time does not regress (slightly faster), and readback matches.
I pushed a commit that drops test_memoryview_layouts (mostly covers existing behavior) and the doc paragraphs (implementation detail). LGTM.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7894 +/- ##
==========================================
- Coverage 58.32% 52.48% -5.84%
==========================================
Files 184 34 -150
Lines 63153 27919 -35234
==========================================
- Hits 36831 14652 -22179
+ Misses 22697 11469 -11228
+ Partials 3625 1798 -1827 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Problem
Client.open(..., "wb")passes a read-onlymemoryviewto_File.write(). Callingtobytes()there copies the whole write before the existing 4 MiB native calls. This is the remaining buffered-copy overhead noted in #7863.Change
Copy large contiguous views one 4 MiB chunk at a time. Keep the direct
bytespath, non-contiguous fallback, and current error/position behavior. Add memory/layout regressions, extend chunk-failure coverage to views, and document the memory boundary.Validation
331de6ea.TestPostgreSQLClienthits its 20-second removed-chunk assertion in the Go non-core job; the aggregate check fails with it. This is being investigated separately.