@playcanvas/splat-transform 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -156,42 +156,38 @@ class DataTable {
156
156
  * After calling, row `i` will contain the data that was previously at row `indices[i]`.
157
157
  *
158
158
  * This is a memory-efficient alternative to `permuteRows` that modifies the table
159
- * in-place rather than creating a copy.
159
+ * in-place rather than creating a copy. It reuses ArrayBuffers between columns to
160
+ * minimize memory allocations.
160
161
  *
161
162
  * @param indices - Array of indices defining the permutation. Must have the same
162
163
  * length as the number of rows, and must be a valid permutation
163
164
  * (each index 0 to n-1 appears exactly once).
164
165
  */
165
166
  permuteRowsInPlace(indices) {
166
- const n = this.numRows;
167
- const numCols = this.columns.length;
168
- const visited = new Uint8Array(n);
169
- const temps = new Array(numCols);
170
- for (let i = 0; i < n; i++) {
171
- if (visited[i] || indices[i] === i)
172
- continue;
173
- // Save values at position i
174
- for (let c = 0; c < numCols; c++) {
175
- temps[c] = this.columns[c].data[i];
167
+ // Cache for reusing ArrayBuffers by size
168
+ const cache = new Map();
169
+ const getBuffer = (size) => {
170
+ const cached = cache.get(size);
171
+ if (cached) {
172
+ cache.delete(size);
173
+ return cached;
176
174
  }
177
- // Walk the cycle
178
- let j = i;
179
- while (true) {
180
- const next = indices[j];
181
- visited[j] = 1;
182
- if (next === i) {
183
- // End of cycle - place saved values
184
- for (let c = 0; c < numCols; c++) {
185
- this.columns[c].data[j] = temps[c];
186
- }
187
- break;
188
- }
189
- // Move values from next to j
190
- for (let c = 0; c < numCols; c++) {
191
- this.columns[c].data[j] = this.columns[c].data[next];
192
- }
193
- j = next;
175
+ return new ArrayBuffer(size);
176
+ };
177
+ const returnBuffer = (buffer) => {
178
+ cache.set(buffer.byteLength, buffer);
179
+ };
180
+ const n = this.numRows;
181
+ for (const column of this.columns) {
182
+ const src = column.data;
183
+ const constructor = src.constructor;
184
+ const dst = new constructor(getBuffer(src.byteLength));
185
+ // Sequential writes are cache-friendly
186
+ for (let i = 0; i < n; i++) {
187
+ dst[i] = src[indices[i]];
194
188
  }
189
+ returnBuffer(src.buffer);
190
+ column.data = dst;
195
191
  }
196
192
  }
197
193
  }
@@ -3722,7 +3718,7 @@ class CompressedChunk {
3722
3718
  }
3723
3719
  }
3724
3720
 
3725
- var version = "1.4.0";
3721
+ var version = "1.4.1";
3726
3722
 
3727
3723
  const generatedByString = `Generated by splat-transform ${version}`;
3728
3724
  const chunkProps = [