@daneren2005/shared-memory-objects 0.0.10 → 0.0.12
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/README.md +82 -3
- package/dist/shared-memory-objects.js +1356 -0
- package/dist/shared-memory-objects.js.map +1 -0
- package/dist/shared-memory-objects.umd.cjs +2 -0
- package/dist/shared-memory-objects.umd.cjs.map +1 -0
- package/dist/src/allocated-memory.d.ts +26 -0
- package/dist/src/cached-item-list.d.ts +37 -0
- package/{src/interfaces/pow2.ts → dist/src/interfaces/pow2.d.ts} +2 -3
- package/dist/src/interfaces/typed-array-constructor.d.ts +5 -0
- package/{src/interfaces/typed-array.ts → dist/src/interfaces/typed-array.d.ts} +1 -1
- package/dist/src/lock/read-write-lock.d.ts +5 -0
- package/dist/src/lock/simple-lock.d.ts +3 -0
- package/dist/src/main.d.ts +18 -0
- package/dist/src/memory-buffer.d.ts +185 -0
- package/dist/src/memory-heap.d.ts +34 -0
- package/dist/src/serialize-object.d.ts +5 -0
- package/dist/src/shared-list.d.ts +44 -0
- package/dist/src/shared-map.d.ts +25 -0
- package/dist/src/shared-pointer-list.d.ts +21 -0
- package/dist/src/shared-pool.d.ts +39 -0
- package/dist/src/shared-string.d.ts +23 -0
- package/dist/src/shared-vector.d.ts +41 -0
- package/dist/src/utils/16-from-32-array.d.ts +4 -0
- package/dist/src/utils/16-from-64-array.d.ts +2 -0
- package/dist/src/utils/float32-atomics.d.ts +5 -0
- package/dist/src/utils/pointer.d.ts +19 -0
- package/package.json +34 -22
- package/src/allocated-memory.ts +0 -89
- package/src/cached-item-list.ts +0 -143
- package/src/interfaces/typed-array-constructor.ts +0 -6
- package/src/lock/read-write-lock.ts +0 -41
- package/src/lock/simple-lock.ts +0 -21
- package/src/main.ts +0 -40
- package/src/memory-buffer.ts +0 -666
- package/src/memory-heap.ts +0 -206
- package/src/serialize-object.ts +0 -95
- package/src/shared-list.ts +0 -339
- package/src/shared-map.ts +0 -252
- package/src/shared-pointer-list.ts +0 -80
- package/src/shared-string.ts +0 -144
- package/src/shared-vector.ts +0 -236
- package/src/utils/16-from-32-array.ts +0 -23
- package/src/utils/16-from-64-array.ts +0 -18
- package/src/utils/float32-atomics.ts +0 -26
- package/src/utils/pointer.ts +0 -40
- package/src/utils/typedarray.js +0 -162
- package/src/vite-env.d.ts +0 -1
- /package/{src → dist/src}/utils/typedarray.d.ts +0 -0
package/README.md
CHANGED
|
@@ -56,9 +56,10 @@ let mainList = new SharedList(memory);
|
|
|
56
56
|
let secondList = new SharedList(memory, mainList.getSharedMemory());
|
|
57
57
|
|
|
58
58
|
## Data Structures
|
|
59
|
-
- SharedList
|
|
60
|
-
- SharedVector
|
|
61
|
-
- SharedMap
|
|
59
|
+
- SharedList - linked list
|
|
60
|
+
- SharedVector - growable array
|
|
61
|
+
- SharedMap - growable hash map
|
|
62
|
+
- SharedPool - stable indexed data with a recycled pool and maximum internal array sizes
|
|
62
63
|
- SharedString
|
|
63
64
|
|
|
64
65
|
## Thread Safety
|
|
@@ -71,5 +72,83 @@ let secondList = new SharedList(memory, mainList.getSharedMemory());
|
|
|
71
72
|
- Make data structures thread safe
|
|
72
73
|
- Add basic thread safe object example
|
|
73
74
|
|
|
75
|
+
## Performance
|
|
76
|
+
The tl;dr is that none of these data structures are close to what you can get by just using native data structures, but I wasn't expecting them to be with their overhead.
|
|
77
|
+
They are all significantly slower at iterating and accessing an indexed location. The SharedList is slowest at everything.
|
|
78
|
+
The SharedPool is the closest to native performance when doing a bunch of random deletes and inserts, which is what I use it for as the memory storage for components in my own ECS framework.
|
|
79
|
+
Since indexed access is about 1/5 the speed of just using a native JS array, there needs to be a lot of work offloaded into a separate thread of make it worth it.
|
|
80
|
+
|
|
81
|
+
Shared Data Structures: 10000 iterations 36242ms
|
|
82
|
+
```
|
|
83
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
84
|
+
shared list 1,178.27 0.7080 1.8484 0.8487 0.9095 1.4762 1.5502 1.8484 ±1.38% 590
|
|
85
|
+
shared vector 2,071.17 0.4084 1.1862 0.4828 0.5102 0.8796 0.9150 1.0795 ±1.31% 1036
|
|
86
|
+
shared pool 1,944.70 0.4563 1.1443 0.5142 0.5139 0.8429 1.0326 1.1443 ±1.09% 973
|
|
87
|
+
native array 392,746.59 0.0021 0.1976 0.0025 0.0023 0.0059 0.0068 0.0148 ±0.25% 196374
|
|
88
|
+
|
|
89
|
+
native array
|
|
90
|
+
189.63x faster than shared vector
|
|
91
|
+
201.96x faster than shared pool
|
|
92
|
+
333.33x faster than shared list
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Shared Data Structures: 1000 indexed locations 4258ms
|
|
96
|
+
```
|
|
97
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
98
|
+
shared vector 28,917.42 0.0311 0.2926 0.0346 0.0328 0.0631 0.0822 0.1994 ±0.50% 14459
|
|
99
|
+
shared pool 20,636.58 0.0446 0.2953 0.0485 0.0464 0.0851 0.1039 0.2063 ±0.45% 10319
|
|
100
|
+
native array 120,189.16 0.0073 0.2456 0.0083 0.0078 0.0144 0.0189 0.1003 ±0.47% 60095
|
|
101
|
+
|
|
102
|
+
native array
|
|
103
|
+
4.16x faster than shared vector
|
|
104
|
+
5.82x faster than shared pool
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Shared Data Structures: 1000 inserts 3685ms
|
|
108
|
+
```
|
|
109
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
110
|
+
shared list 2,154.19 0.4107 1.1497 0.4642 0.4531 0.8892 0.9123 1.0928 ±1.14% 1078
|
|
111
|
+
shared map 105.46 8.3417 15.2814 9.4824 9.5396 15.2814 15.2814 15.2814 ±4.05% 53
|
|
112
|
+
shared vector 11,058.22 0.0799 0.3675 0.0904 0.0863 0.2084 0.2340 0.2833 ±0.66% 5530
|
|
113
|
+
shared vector with correct amount initialized 16,369.28 0.0548 0.2825 0.0611 0.0575 0.1462 0.1620 0.2008 ±0.56% 8185
|
|
114
|
+
shared pool 10,653.47 0.0835 0.3480 0.0939 0.0900 0.2041 0.2222 0.2877 ±0.61% 5327
|
|
115
|
+
native array 96,437.13 0.0079 0.2799 0.0104 0.0097 0.0234 0.0681 0.1194 ±0.63% 48219
|
|
116
|
+
|
|
117
|
+
native array
|
|
118
|
+
5.89x faster than shared vector with correct amount initialized
|
|
119
|
+
8.72x faster than shared vector
|
|
120
|
+
9.37x faster than shared pool
|
|
121
|
+
44.77x faster than shared list
|
|
122
|
+
914.45x faster than shared map
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Shared Data Structures: 1000 deletes random element 3803ms
|
|
126
|
+
```
|
|
127
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
128
|
+
shared list 15.0673 61.7598 82.5745 66.3688 66.1354 82.5745 82.5745 82.5745 ±6.77% 10
|
|
129
|
+
shared vector 392.32 2.3210 3.3845 2.5490 2.6034 3.2132 3.3845 3.3845 ±0.87% 197
|
|
130
|
+
shared pool 7,863.80 0.1107 0.6587 0.1272 0.1214 0.2658 0.2978 0.3581 ±0.76% 3932
|
|
131
|
+
native array 11,069.38 0.0810 0.2720 0.0903 0.0884 0.1469 0.1695 0.2330 ±0.39% 5536
|
|
132
|
+
|
|
133
|
+
native array
|
|
134
|
+
1.41x faster than shared pool
|
|
135
|
+
28.22x faster than shared vector
|
|
136
|
+
734.66x faster than shared list
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Shared Data Structures: 1000 insert and deleting random elements 3046ms
|
|
140
|
+
```
|
|
141
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
142
|
+
shared list 23.7748 39.9588 45.1601 42.0613 42.5335 45.1601 45.1601 45.1601 ±2.42% 12
|
|
143
|
+
shared vector 902.76 0.9947 1.8245 1.1077 1.1230 1.5256 1.5723 1.8245 ±0.83% 452
|
|
144
|
+
shared pool 4,595.05 0.1917 0.5539 0.2176 0.2092 0.3902 0.4076 0.4921 ±0.73% 2298
|
|
145
|
+
native array 11,004.28 0.0785 0.3460 0.0909 0.0872 0.1865 0.2116 0.2406 ±0.54% 5503
|
|
146
|
+
|
|
147
|
+
native array
|
|
148
|
+
2.39x faster than shared pool
|
|
149
|
+
12.19x faster than shared vector
|
|
150
|
+
462.85x faster than shared list
|
|
151
|
+
```
|
|
152
|
+
|
|
74
153
|
## Credit
|
|
75
154
|
The entire core of this library is based on a fork of @thi.ng/malloc found at https://github.com/thi-ng/umbrella/blob/develop/packages/malloc. The only big difference between our MemoryBuffer and their MemPool is making allocations/freeing memory thread safe.
|