Commit 805ecdc
Pool the dictionary buffer when training a Zstandard dictionary
ZstandardDictionary.Train allocated 'new byte[maxDictionarySize]' on every call. Dictionary sizes are typically tens to hundreds of KB (zstd recommends up to ~100 KB, but the API allows more), so each training call paid for a fresh GC allocation that often landed on the LOH.
Rent the buffer from ArrayPool<byte>.Shared instead. Create copies the trained slice into an exact-sized array before returning, so the rented buffer can be returned immediately. Use clearArray: true on Return because the trained dictionary is derived from caller-supplied samples and must not linger in the shared pool.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1547c9a commit 805ecdc
1 file changed
Lines changed: 21 additions & 14 deletions
File tree
- src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard
Lines changed: 21 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 130 | + | |
| 131 | + | |
135 | 132 | | |
136 | | - | |
137 | | - | |
138 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
139 | 136 | | |
140 | | - | |
141 | | - | |
142 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
143 | 148 | | |
144 | | - | |
145 | | - | |
146 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
147 | 154 | | |
148 | 155 | | |
149 | 156 | | |
| |||
0 commit comments