feat(v8/scripting): swap from msgpack-lite to msgpackr#3018
feat(v8/scripting): swap from msgpack-lite to msgpackr#3018AvarianKnight wants to merge 2 commits into
Conversation
Co-authored-by: Linden <65407488+thelindat@users.noreply.github.com>
| throw new Error('Unknown extension type ' + type) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
We should probably just handle the conversions here anyways, since sending vectors to/from scrts is currently very hacky and I doubt may people do it currently.
There was a problem hiding this comment.
Created an array containing 100 objects and another with 1000 objects. Performed 1000 iterations.
msgpack-lite
Running benchmark for packing...
Pack - Min: 0.0568 ms, Max: 1.1691 ms, Avg: 0.080365 ms
Running benchmark for unpacking...
Unpack - Min: 0.0482 ms, Max: 1.1444 ms, Avg: 0.061173 ms
Running benchmark for packing...
Pack - Min: 5.2618 ms, Max: 13.8522 ms, Avg: 5.99034 ms
Running benchmark for unpacking...
Unpack - Min: 5.0637 ms, Max: 20.6582 ms, Avg: 5.366889 ms
msgpackr
Running benchmark for packing...
Pack - Min: 0.0185 ms, Max: 4.2132 ms, Avg: 0.03549 ms
Running benchmark for unpacking...
Unpack - Min: 0.035 ms, Max: 1.9161 ms, Avg: 0.059167 ms
Running benchmark for packing...
Pack - Min: 1.8215 ms, Max: 10.3579 ms, Avg: 1.995244 ms
Running benchmark for unpacking...
Unpack - Min: 3.4534 ms, Max: 18.5718 ms, Avg: 3.717805 ms
Edit
const curtime = process.hrtime.bigint;
const results = [];
function runBenchmark(iterations, title, func) {
const start = curtime();
for (let i = 0; i < iterations; i++) {
func();
}
results.push([Number(curtime() - start) / iterations, title]);
}
function showResults(iterations) {
console.log(`Average results from ${iterations} iterations (ms)`);
results.sort((a, b) => a[1] < b[1]);
for (let i = 0; i < results.length; i++) {
const result = results[i];
console.log(`#${i + 1} - ${(result[0] / 1e6).toFixed(4)}\t(${result[1]})`);
}
const copy = [...results];
results.length = 0;
return copy;
}
async function benchmark(iterations, obj) {
for (k in obj) {
await new Promise((r) => setTimeout(r, 100));
runBenchmark(iterations, k, obj[k]);
}
return showResults(iterations);
}
setTimeout(async () => {
const data = new Array(100000);
data.fill("avarian smells");
const packed = pack(data);
const fn = {
Packing: () => pack(data),
Unpacking: () => unpack(packed),
};
const result = await benchmark(100, fn);
}, 500);msgpack-lite
Average results from 100 iterations (ms)
1 - 10.5856 (Packing)
2 - 26.7245 (Unpacking)
msgpackr
Average results from 100 iterations (ms)
1 - 3.9559 (Packing)
2 - 9.0236 (Unpacking)
For a ~62-66% increase in speed. For a larger array (1000000 elements) this was about ~45-53%.
|
When testing this caused crashing for RedM due to how it's session manager works, I'll look into this when I have the time |
Update msgpack.js
|
Superseded by #3201 |
Goal of this PR
Swap JS to msgpackr to allow serializing classes & other js builtin objects (i.e.
Map,Set,Error, etc) and also increase performance.How is this PR achieving the goal
Swap out the custom version of msgpack-lite to use msgpackr
This PR applies to the following area(s)
ScRT: JS
Successfully tested on
Game builds: N/A
Platforms: Windows, Linux
Checklist
Fixes issues
Supersedes PR #2931