Skip to content

sdk/python: bound temporary copies in large buffered writes - #7894

Merged
jiefenghuang merged 3 commits into
juicedata:mainfrom
adenzhou1350:codex/bound-python-write-buffer-copy
Nov 24, 2026
Merged

jiefenghuang merged 3 commits into
juicedata:mainfrom
adenzhou1350:codex/bound-python-write-buffer-copy

Conversation

@adenzhou1350

@adenzhou1350 adenzhou1350 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Client.open(..., "wb") passes a read-only memoryview to _File.write(). Calling tobytes() 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 bytes path, non-contiguous fallback, and current error/position behavior. Add memory/layout regressions, extend chunk-failure coverage to views, and document the memory boundary.

Validation

  • Linux/Python 3.12, real libjfs, private SQLite metadata + file storage: identical 25-test cohort gives 24 pass/1 fail before, 25 pass after. The failure is the new 32 MiB buffered-write allocation test.
  • Four fresh processes in A/B/B/A order, 128 MiB buffered writes with full SHA256 readback: Python traced peak temporary allocation 128 MiB → 8 MiB. Input allocation is excluded; this is not total memory or a throughput claim. The 256 KiB control stays unchanged.
  • Pinned EOF/whitespace hooks and diff check pass. Local runs reuse libjfs from 331de6ea.
  • Hosted CI: complete Redis/MySQL/TiKV SDK jobs pass with fresh native builds (Redis SDK suite: 80 tests).
  • Remaining CI failure: TestPostgreSQLClient hits its 20-second removed-chunk assertion in the Go non-core job; the aggregate check fails with it. This is being investigated separately.

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>

@zxh326 zxh326 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.48%. Comparing base (23d2a45) to head (a5e6160).
⚠️ Report is 6 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jiefenghuang
jiefenghuang merged commit f0826be into juicedata:main Nov 24, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants