Skip to content

Conversation

@ThomasWaldmann
Copy link
Member

@ThomasWaldmann ThomasWaldmann commented Dec 31, 2025

No description provided.

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.59%. Comparing base (af232a5) to head (4eed3ec).
⚠️ Report is 4 commits behind head on 1.4-maint.

Additional details and impacted files
@@            Coverage Diff             @@
##           1.4-maint    #9246   +/-   ##
==========================================
  Coverage      80.59%   80.59%           
==========================================
  Files             38       38           
  Lines          11256    11256           
  Branches        1771     1771           
==========================================
  Hits            9072     9072           
  Misses          1615     1615           
  Partials         569      569           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann ThomasWaldmann changed the title mount: fix write_offset, #9245 mount: fix edge cases, async safety, #9245 Dec 31, 2025
@ThomasWaldmann ThomasWaldmann marked this pull request as draft December 31, 2025 17:16
@ThomasWaldmann ThomasWaldmann changed the title mount: fix edge cases, async safety, #9245 mount: fuse fs fixes Jan 1, 2026
### Performance Comparison: `bytearray.extend()` vs. Concatenation

The efficiency difference between `meta.extend(bytes(N))` and `meta = meta + bytes(N)` stems from how Python manages memory and objects during these operations.

#### 1. In-Place Modification vs. Object Creation
- **`bytearray.extend()`**: This is an **in-place** operation. If the current memory block allocated for the `bytearray` has enough extra capacity (pre-allocated space), Python simply writes the new bytes into that space and updates the length. If it needs more space, it uses `realloc()`, which can often expand the existing memory block without moving the entire data set to a new location.
- **Concatenation (`+`)**: This creates a **completely new** `bytearray` object. It allocates a new memory block large enough to hold the sum of both parts, copies the contents of `meta`, copies the contents of `bytes(N)`, and then reassigns the variable `meta` to this new object.

#### 2. Computational Complexity
- **`bytearray.extend()`**: In the best case (when capacity exists), it is **O(K)**, where K is the number of bytes being added. In the worst case (reallocation), it is **O(N + K)**, but Python uses an over-allocation strategy (growth factor) that amortizes this cost, making it significantly faster on average.
- **Concatenation (`+`)**: It is always **O(N + K)** because it must copy the existing `N` bytes every single time. As the `bytearray` grows larger (e.g., millions of items in a backup), this leads to **O(N²)** total time complexity across multiple additions, as you are repeatedly copying an ever-growing buffer.

#### 3. Memory Pressure and Garbage Collection
- Concatenation briefly requires memory for **both** the old buffer and the new buffer simultaneously before the old one is garbage collected. This increases the peak memory usage of the process.
- `extend()` is more memory-efficient as it minimizes the need for multiple large allocations and relies on the underlying memory manager's ability to resize buffers efficiently.

In the context of `borg mount`, where `meta` can grow to be many megabytes or even gigabytes for very large repositories, using concatenation causes a noticeable slowdown as the number of archives or files increases, whereas `extend()` remains performant.
@ThomasWaldmann ThomasWaldmann marked this pull request as ready for review January 3, 2026 18:47
@ThomasWaldmann ThomasWaldmann changed the title mount: fuse fs fixes mount: fuse fs performance fix, docstring Jan 3, 2026
@ThomasWaldmann ThomasWaldmann merged commit 70c87b6 into borgbackup:1.4-maint Jan 4, 2026
21 of 22 checks passed
@ThomasWaldmann ThomasWaldmann deleted the fuse-fixes-1.4 branch January 4, 2026 03:38
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Backport failed for master, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin master
git worktree add -d .worktree/backport-9246-to-master origin/master
cd .worktree/backport-9246-to-master
git switch --create backport-9246-to-master
git cherry-pick -x 646f279062faad0b88c2feeff2e0d9a9cf675a2a 4eed3ecd5b378c8cd899fd3fe89df001f7d43a65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant