@daneren2005/shared-memory-objects 0.0.17 → 0.0.19
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 +57 -43
- package/dist/shared-memory-objects.js +381 -280
- package/dist/shared-memory-objects.js.map +1 -1
- package/dist/shared-memory-objects.umd.cjs +1 -1
- package/dist/shared-memory-objects.umd.cjs.map +1 -1
- package/dist/src/local-pool.d.ts +31 -0
- package/dist/src/main.d.ts +2 -1
- package/dist/src/shared-pool.d.ts +1 -0
- package/dist/src/shared-vector.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,12 +59,13 @@ let secondList = new SharedList(memory, mainList.getSharedMemory());
|
|
|
59
59
|
- SharedList - linked list
|
|
60
60
|
- SharedVector - growable array
|
|
61
61
|
- SharedMap - growable hash map
|
|
62
|
+
- LocalPool - stable indexed data with a recycled pool that can only be pushed/deleted from main thread but can pass TypedArrays to other threads to operate on
|
|
62
63
|
- SharedPool - stable indexed data with a recycled pool and maximum internal array sizes
|
|
63
64
|
- SharedString
|
|
64
65
|
|
|
65
66
|
## Thread Safety
|
|
66
67
|
- Memory allocations is thread safe as long as it does not need to create a new buffer. Right now that can only be done from the main thread.
|
|
67
|
-
- SharedList, SharedVector, and SharedMap are all not thread safe.
|
|
68
|
+
- SharedList, SharedVector, SharedPool, and SharedMap are all not thread safe.
|
|
68
69
|
- SharedString is thread safe with a lock on read/write with a cached version of the string so it doesn't need to lock after the first read unless the string has changed.
|
|
69
70
|
|
|
70
71
|
## TODO
|
|
@@ -75,79 +76,92 @@ let secondList = new SharedList(memory, mainList.getSharedMemory());
|
|
|
75
76
|
## Performance
|
|
76
77
|
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
78
|
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
|
+
The SharedPool/LocalPool 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
80
|
Since indexed access is about 1/4 the speed of just using a native JS array, there needs to be a lot of work offloaded into a separate thread to make it worth it.
|
|
80
81
|
|
|
81
82
|
Shared Data Structures: 10000 iterations
|
|
82
83
|
```
|
|
83
84
|
name hz min max mean p75 p99 p995 p999 rme samples
|
|
84
|
-
shared list 1,
|
|
85
|
-
shared vector 2,
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
shared list 1,040.61 0.7898 2.1673 0.9610 1.0080 1.6299 1.7740 2.1673 ±1.49% 521
|
|
86
|
+
shared vector 2,447.08 0.3489 0.8944 0.4086 0.4369 0.7289 0.7887 0.8457 ±1.12% 1224
|
|
87
|
+
local pool 2,661.05 0.3266 0.9810 0.3758 0.3751 0.6516 0.7423 0.9332 ±1.05% 1331
|
|
88
|
+
shared pool 2,052.60 0.4255 1.1583 0.4872 0.4878 0.8323 0.8735 1.0186 ±1.10% 1027
|
|
89
|
+
native array 379,950.63 0.0021 0.1505 0.0026 0.0023 0.0062 0.0070 0.0218 ±0.28% 189976
|
|
88
90
|
|
|
89
91
|
native array
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
142.78x faster than local pool
|
|
93
|
+
155.27x faster than shared vector
|
|
94
|
+
185.11x faster than shared pool
|
|
95
|
+
365.12x faster than shared list
|
|
93
96
|
```
|
|
94
97
|
|
|
95
98
|
Shared Data Structures: 1000 indexed locations
|
|
96
99
|
```
|
|
97
100
|
name hz min max mean p75 p99 p995 p999 rme samples
|
|
98
|
-
shared vector
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
shared vector 28,713.93 0.0276 1.1649 0.0348 0.0335 0.0767 0.1276 0.2245 ±0.86% 14357
|
|
102
|
+
local pool 88,708.78 0.0099 0.2418 0.0113 0.0105 0.0192 0.0261 0.1700 ±0.62% 44369
|
|
103
|
+
shared pool 33,795.16 0.0270 0.1868 0.0296 0.0287 0.0536 0.0631 0.1376 ±0.36% 16898
|
|
104
|
+
native array 126,855.06 0.0072 0.2046 0.0079 0.0076 0.0129 0.0146 0.0993 ±0.42% 63428
|
|
101
105
|
|
|
102
106
|
native array
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
1.43x faster than local pool
|
|
108
|
+
3.75x faster than shared pool
|
|
109
|
+
4.42x faster than shared vector
|
|
105
110
|
```
|
|
106
111
|
|
|
107
112
|
Shared Data Structures: 1000 inserts
|
|
108
113
|
```
|
|
109
114
|
name hz min max mean p75 p99 p995 p999 rme samples
|
|
110
|
-
shared list
|
|
111
|
-
shared map
|
|
112
|
-
shared vector
|
|
113
|
-
shared vector with correct amount initialized
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
shared list 1,989.04 0.4176 1.2361 0.5028 0.5238 0.9547 1.0934 1.2361 ±1.49% 995
|
|
116
|
+
shared map 98.3711 8.8636 13.3231 10.1656 10.7163 13.3231 13.3231 13.3231 ±3.14% 50
|
|
117
|
+
shared vector 15,559.65 0.0529 0.4758 0.0643 0.0609 0.1405 0.1849 0.2850 ±0.71% 7780
|
|
118
|
+
shared vector with correct amount initialized 22,386.17 0.0372 0.3258 0.0447 0.0415 0.0968 0.1167 0.2119 ±0.61% 11194
|
|
119
|
+
local pool 43,012.42 0.0173 0.3407 0.0232 0.0210 0.0706 0.0933 0.2009 ±0.79% 21507
|
|
120
|
+
shared pool 9,873.77 0.0794 0.5068 0.1013 0.1013 0.2696 0.3232 0.4319 ±1.06% 4937
|
|
121
|
+
shared pool with already deleted elements 13,396.59 0.0643 0.3341 0.0746 0.0700 0.1830 0.2322 0.2799 ±0.70% 6699
|
|
122
|
+
native array 94,368.06 0.0084 0.4662 0.0106 0.0101 0.0236 0.0498 0.1181 ±0.61% 47186
|
|
116
123
|
|
|
117
124
|
native array
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
2.19x faster than local pool
|
|
126
|
+
4.22x faster than shared vector with correct amount initialized
|
|
127
|
+
6.06x faster than shared vector
|
|
128
|
+
7.04x faster than shared pool with already deleted elements
|
|
129
|
+
9.56x faster than shared pool
|
|
130
|
+
47.44x faster than shared list
|
|
131
|
+
959.31x faster than shared map
|
|
123
132
|
```
|
|
124
133
|
|
|
125
134
|
Shared Data Structures: 1000 deletes random element
|
|
135
|
+
NOTE: Local pool is faster than native because array slice is slower than push/pop to a native recycle array
|
|
126
136
|
```
|
|
127
137
|
name hz min max mean p75 p99 p995 p999 rme samples
|
|
128
|
-
shared list
|
|
129
|
-
shared vector
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
shared list 13.1818 68.1220 83.8157 75.8622 79.3236 83.8157 83.8157 83.8157 ±4.40% 10
|
|
139
|
+
shared vector 387.53 2.3857 3.0819 2.5804 2.6409 3.0624 3.0819 3.0819 ±0.70% 194
|
|
140
|
+
local pool 71,370.27 0.0105 0.5406 0.0140 0.0122 0.1055 0.1351 0.1960 ±1.07% 35686
|
|
141
|
+
shared pool 13,049.38 0.0689 0.2990 0.0766 0.0746 0.1439 0.1681 0.2269 ±0.51% 6525
|
|
142
|
+
native array 10,559.95 0.0827 0.2363 0.0947 0.0941 0.1532 0.1693 0.2037 ±0.45% 5281
|
|
143
|
+
|
|
144
|
+
local pool
|
|
145
|
+
5.47x faster than shared pool
|
|
146
|
+
6.76x faster than native array
|
|
147
|
+
184.17x faster than shared vector
|
|
148
|
+
5414.30x faster than shared list
|
|
137
149
|
```
|
|
138
150
|
|
|
139
151
|
Shared Data Structures: 1000 insert and deleting random elements
|
|
140
152
|
```
|
|
141
153
|
name hz min max mean p75 p99 p995 p999 rme samples
|
|
142
|
-
shared list
|
|
143
|
-
shared vector
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
shared list 20.5573 43.7463 57.7009 48.6445 50.4710 57.7009 57.7009 57.7009 ±5.73% 11
|
|
155
|
+
shared vector 752.07 1.0805 2.4937 1.3297 1.3769 2.1734 2.3537 2.4937 ±1.81% 377
|
|
156
|
+
local pool 22,453.72 0.0388 0.3417 0.0445 0.0417 0.1214 0.1574 0.2231 ±0.63% 11227
|
|
157
|
+
shared pool 5,684.68 0.1490 1.7416 0.1759 0.1703 0.4351 0.5387 0.9790 ±1.37% 2843
|
|
158
|
+
native array 11,030.10 0.0793 0.2980 0.0907 0.0866 0.1808 0.1976 0.2412 ±0.54% 5516
|
|
159
|
+
|
|
160
|
+
local pool
|
|
161
|
+
2.04x faster than native array
|
|
162
|
+
3.95x faster than shared pool
|
|
163
|
+
29.86x faster than shared vector
|
|
164
|
+
1092.25x faster than shared list
|
|
151
165
|
```
|
|
152
166
|
|
|
153
167
|
## Credit
|