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