Commit 5586a4c
committed
Reduce home-dir scan peak RSS by deferring + slimming intermediate copies
Three changes, all aimed at not having multiple full-size copies of a
~6M-row DataFrame coexisting at the peak (final concat + parquet write):
1. `find/index.py`: the upward-aggregation loop only needs 5 columns
(`path`, `parent`, `size`, `mtime`, `n_desc`). Slicing those out
before the loop means each per-level `.copy()` drags 5 string/int
columns instead of 8 (which had included the wide `uri` column).
2. `find/index.py`: defer the `files = df[df.kind == 'file']` slice
until the final `index-agg-dirs` step. The agg loop doesn't need
file rows in their wide form, and holding the slice during the loop
kept ~half the dataset duplicated for no benefit.
3. `storage/hybrid.py`: the chunk-write loop used to copy the full df
once upfront, then for each large subtree do `df[mask].copy()`
followed by `_rebase_paths(...).copy()` — three copies in flight
per chunk write. Now we (a) skip the upfront full-df copy, (b)
extract+rebase each subtree into a single new df via `assign`, and
(c) explicitly `del` it before falling through to the next iteration.
Per-iteration `to_parquet` now goes through an internal helper that
converts to `pyarrow.Table`, drops the pandas frame, then writes — so
peak no longer holds both the Python string objects and the Arrow
string buffers simultaneously.
Measured via `ru_maxrss` sampling on a 6M-file home dir: peak RSS holds
around 2.98 GiB throughout, with the growth concentrated in the final
concat + parquet write step. (memray's `peak_memory` with
`native_traces=True` was reporting much higher numbers because it
includes native-allocator bookkeeping — RSS is the operationally
meaningful figure.)1 parent 0ec72c0 commit 5586a4c
2 files changed
Lines changed: 84 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | | - | |
| 63 | + | |
| 64 | + | |
57 | 65 | | |
58 | | - | |
| 66 | + | |
| 67 | + | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
62 | | - | |
63 | | - | |
| 71 | + | |
| 72 | + | |
64 | 73 | | |
65 | 74 | | |
66 | 75 | | |
67 | | - | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
71 | 99 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
75 | 103 | | |
76 | | - | |
77 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
78 | 108 | | |
79 | | - | |
80 | | - | |
| 109 | + | |
| 110 | + | |
81 | 111 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
85 | 116 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
89 | 123 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
93 | 132 | | |
94 | | - | |
95 | | - | |
96 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
97 | 139 | | |
98 | 140 | | |
99 | 141 | | |
| |||
102 | 144 | | |
103 | 145 | | |
104 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
105 | 158 | | |
106 | 159 | | |
107 | 160 | | |
| |||
0 commit comments