-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: implement structuredClone in native
Simplify the implementation by implementing it directly in C++. For now we still piggyback on the MessagePort implementation, this can be simplified further by avoiding MessagePorts at all in the future.
- Loading branch information
1 parent
97d2219
commit 81ff9d9
Showing
9 changed files
with
264 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['string', 'object', 'arraybuffer'], | ||
n: [1e4], | ||
}); | ||
|
||
function main({ n, type }) { | ||
const data = []; | ||
|
||
switch (type) { | ||
case 'string': | ||
for (let i = 0; i < n; ++i) { | ||
data.push(new Date().toISOString()); | ||
} | ||
break; | ||
case 'object': | ||
for (let i = 0; i < n; ++i) { | ||
data.push({ ...process.config }); | ||
} | ||
break; | ||
case 'arraybuffer': | ||
for (let i = 0; i < n; ++i) { | ||
data.push(new ArrayBuffer(10)); | ||
} | ||
break; | ||
default: | ||
throw new Error('Unsupported payload type'); | ||
} | ||
|
||
const run = type === 'arraybuffer' ? (i) => { | ||
data[i] = structuredClone(data[i], { transfer: [ data[i] ] }); | ||
} : (i) => { | ||
data[i] = structuredClone(data[i]); | ||
}; | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; ++i) { | ||
run(i); | ||
} | ||
bench.end(n); | ||
assert.strictEqual(data.length, n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.