Commit d638132
feat(perf): Optimize ShareableMap and ShareableArray defragmentation
- Replaces slow `DataView` byte-by-byte copying with a hybrid `Uint8Array` strategy.
- Uses manual loops for small blocks (<64 bytes) to avoid TypedArray view creation overhead.
- Uses `Uint8Array.prototype.set` with `subarray` for larger blocks to leverage native optimized copying.
- Fixes a bug in `ShareableArray.defragment` where `DATA_OBJECT_OFFSET` was added twice to the data pointer, causing memory gaps.
Performance impact:
- Reduces `ShareableMap` defragmentation time by ~14% in tests.
- Significantly faster copying for larger items.
- Fixes incorrect memory usage in `ShareableArray`.
Co-authored-by: pverscha <9608686+pverscha@users.noreply.github.com>1 parent ba797cc commit d638132
3 files changed
Lines changed: 26 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
945 | 945 | | |
946 | 946 | | |
947 | 947 | | |
948 | | - | |
| 948 | + | |
| 949 | + | |
949 | 950 | | |
950 | 951 | | |
951 | 952 | | |
| |||
955 | 956 | | |
956 | 957 | | |
957 | 958 | | |
958 | | - | |
959 | | - | |
960 | | - | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
961 | 967 | | |
962 | 968 | | |
963 | 969 | | |
964 | 970 | | |
965 | 971 | | |
966 | 972 | | |
967 | | - | |
| 973 | + | |
968 | 974 | | |
969 | 975 | | |
970 | 976 | | |
971 | | - | |
972 | | - | |
| 977 | + | |
973 | 978 | | |
974 | 979 | | |
975 | 980 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
| 538 | + | |
| 539 | + | |
538 | 540 | | |
539 | 541 | | |
540 | 542 | | |
| |||
550 | 552 | | |
551 | 553 | | |
552 | 554 | | |
553 | | - | |
554 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
| |||
571 | 579 | | |
572 | 580 | | |
573 | 581 | | |
574 | | - | |
575 | | - | |
| 582 | + | |
576 | 583 | | |
577 | 584 | | |
578 | 585 | | |
| |||
0 commit comments