GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: speed up AbortSignal · nodejs/node@6fef75c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/abort_controller
    • abort-controller-abort.js
    • abort-signal-add-remove.js
    • abort-signal-any.js
  • lib/internal
    • abort_controller.js
    • event_target.js
  • test
    • fixtures/test-runner/output
      • abort.snapshot
      • abort_hooks.snapshot
      • abort_suite.snapshot
    • parallel
      • test-abortcontroller-default-reason-gc.mjs
      • test-abortsignal-any.mjs
      • test-abortsignal-drop-settled-signals.mjs
      • test-eventtarget.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/abort_controller/abort-controller-abort.js‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
n: [1e6],
6+
listeners: [0, 1],
7+
});
8+
9+
function main({ n, listeners }) {
10+
const reason = new Error('reason');
11+
const noop = () => {};
12+
13+
bench.start();
14+
for (let i = 0; i < n; i++) {
15+
const ac = new AbortController();
16+
if (listeners > 0)
17+
ac.signal.addEventListener('abort', noop);
18+
ac.abort(reason);
19+
}
20+
bench.end(n);
21+
}
Collapse file

‎benchmark/abort_controller/abort-signal-add-remove.js‎

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { addAbortListener } = require('events');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e6],
7+
kind: ['addEventListener', 'addEventListener-once', 'addAbortListener'],
8+
});
9+
10+
function main({ n, kind }) {
11+
const { signal } = new AbortController();
12+
const noop = () => {};
13+
14+
switch (kind) {
15+
case 'addEventListener':
16+
bench.start();
17+
for (let i = 0; i < n; i++) {
18+
signal.addEventListener('abort', noop);
19+
signal.removeEventListener('abort', noop);
20+
}
21+
bench.end(n);
22+
break;
23+
case 'addEventListener-once': {
24+
const options = { once: true };
25+
bench.start();
26+
for (let i = 0; i < n; i++) {
27+
signal.addEventListener('abort', noop, options);
28+
signal.removeEventListener('abort', noop);
29+
}
30+
bench.end(n);
31+
break;
32+
}
33+
case 'addAbortListener':
34+
bench.start();
35+
for (let i = 0; i < n; i++) {
36+
addAbortListener(signal, noop)[Symbol.dispose]();
37+
}
38+
bench.end(n);
39+
break;
40+
default:
41+
throw new Error('Invalid kind');
42+
}
43+
}
Collapse file

‎benchmark/abort_controller/abort-signal-any.js‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
n: [2e5],
6+
kind: ['create', 'listen', 'abort'],
7+
});
8+
9+
// Combines a per-iteration signal with a long-lived one, like a request
10+
// signal combined with a server wide one. The work is split into batches
11+
// that run in separate macrotasks because WeakRef targets are kept alive
12+
// until the end of the current job, as they would be between requests.
13+
function main({ n, kind }) {
14+
const reason = new Error('reason');
15+
const noop = () => {};
16+
const longLived = new AbortController().signal;
17+
const batch = 1000;
18+
19+
function run(count) {
20+
for (let i = 0; i < count; i++) {
21+
const ac = new AbortController();
22+
const signal = AbortSignal.any([ac.signal, longLived]);
23+
if (kind === 'create')
24+
continue;
25+
signal.addEventListener('abort', noop, { once: true });
26+
if (kind === 'listen')
27+
signal.removeEventListener('abort', noop);
28+
else
29+
ac.abort(reason);
30+
}
31+
}
32+
33+
let left = n;
34+
function step() {
35+
const count = Math.min(batch, left);
36+
run(count);
37+
left -= count;
38+
if (left > 0)
39+
setImmediate(step);
40+
else
41+
bench.end(n);
42+
}
43+
44+
bench.start();
45+
step();
46+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.