@daneren2005/shared-memory-objects 0.0.11 → 0.0.13
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 +621 -444
- package/dist/shared-memory-objects.js.map +1 -0
- package/dist/shared-memory-objects.umd.cjs +2 -1
- package/dist/shared-memory-objects.umd.cjs.map +1 -0
- package/dist/src/main.d.ts +2 -1
- package/dist/src/shared-pool.d.ts +40 -0
- package/dist/src/shared-vector.d.ts +2 -1
- package/package.json +23 -23
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/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
|
+
Shared Data Structures: 10000 iterations
|
|
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
|
|
96
|
+
```
|
|
97
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
98
|
+
shared vector 27,325.20 0.0313 0.3615 0.0366 0.0333 0.0689 0.0859 0.2216 ±0.60% 13663
|
|
99
|
+
shared pool 31,568.26 0.0272 0.2785 0.0317 0.0295 0.0583 0.0692 0.1803 ±0.50% 15785
|
|
100
|
+
native array 114,517.08 0.0074 0.2652 0.0087 0.0079 0.0171 0.0254 0.1205 ±0.56% 57259
|
|
101
|
+
|
|
102
|
+
native array
|
|
103
|
+
3.63x faster than shared pool
|
|
104
|
+
4.19x faster than shared vector
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Shared Data Structures: 1000 inserts
|
|
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
|
|
126
|
+
```
|
|
127
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
128
|
+
shared list 14.1243 60.2658 82.0964 70.7998 77.6842 82.0964 82.0964 82.0964 ±6.93% 10
|
|
129
|
+
shared vector 393.31 2.3719 3.4563 2.5425 2.5639 3.3824 3.4563 3.4563 ±0.81% 197
|
|
130
|
+
shared pool 8,824.76 0.1005 0.4998 0.1133 0.1085 0.2338 0.2631 0.3420 ±0.72% 4413
|
|
131
|
+
native array 10,750.49 0.0829 0.6180 0.0930 0.0908 0.1494 0.1592 0.2420 ±0.45% 5376
|
|
132
|
+
|
|
133
|
+
native array
|
|
134
|
+
1.22x faster than shared pool
|
|
135
|
+
27.33x faster than shared vector
|
|
136
|
+
761.13x faster than shared list
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Shared Data Structures: 1000 insert and deleting random elements
|
|
140
|
+
```
|
|
141
|
+
name hz min max mean p75 p99 p995 p999 rme samples
|
|
142
|
+
shared list 23.3898 40.4675 46.8902 42.7537 43.4073 46.8902 46.8902 46.8902 ±3.04% 12
|
|
143
|
+
shared vector 848.84 1.0093 2.1141 1.1781 1.1890 1.9349 1.9559 2.1141 ±1.42% 425
|
|
144
|
+
shared pool 4,862.78 0.1822 0.6673 0.2056 0.1974 0.3683 0.3796 0.4319 ±0.75% 2432
|
|
145
|
+
native array 10,584.21 0.0808 0.3616 0.0945 0.0897 0.2304 0.2540 0.3033 ±0.71% 5293
|
|
146
|
+
|
|
147
|
+
native array
|
|
148
|
+
2.18x faster than shared pool
|
|
149
|
+
12.47x faster than shared vector
|
|
150
|
+
452.51x 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.
|