Skip to content

Commit f65dc0e

Browse files
committed
chore: update benchmarks
1 parent d7d634e commit f65dc0e

File tree

17 files changed

+341
-215
lines changed

17 files changed

+341
-215
lines changed

bench/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
"license": "ISC",
1414
"dependencies": {
1515
"@angular/core": "16.0.0-next.0",
16+
"@legendapp/state": "^3.0.0-beta.23",
1617
"@preact/signals": "^1.1.3",
1718
"@reactively/core": "^0.0.8",
1819
"@solidjs/reactivity": "^0.0.9",
1920
"@vue/reactivity": "^3.2.47",
21+
"alien-signals": "^1.0.0",
2022
"compostate": "^0.5.1",
2123
"jotai": "^2.9.1",
2224
"kairo": "0.6.0-rc.0",

bench/pnpm-lock.yaml

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bench/src/cellxBench.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// The following is an implementation of the cellx benchmark https://github.com/Riim/cellx/blob/master/perf/perf.html
2-
import { logPerfResult } from './util/perfLogging'
2+
import { assert, logPerfResult } from './util/perfLogging'
33
import { Computed, ReactiveFramework } from './util/reactiveFramework'
44

55
const cellx = (framework: ReactiveFramework, layers: number) => {
@@ -125,12 +125,12 @@ export const cellxbench = (framework: ReactiveFramework) => {
125125
const [before, after] = results[layers]
126126
const [expectedBefore, expectedAfter] = expected[layers]
127127

128-
console.assert(
128+
assert(
129129
arraysEqual(before, expectedBefore),
130130
`Expected first layer ${expectedBefore}, found first layer ${before}`
131131
)
132132

133-
console.assert(
133+
assert(
134134
arraysEqual(after, expectedAfter),
135135
`Expected last layer ${expectedAfter}, found last layer ${after}`
136136
)

bench/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { TestConfig, FrameworkInfo } from './util/frameworkTypes'
22

3+
import { alienFramework } from './frameworks/alienSignals'
34
import { angularFramework } from './frameworks/angularSignals'
45
import { compostateFramework } from './frameworks/compostate'
56
import { jotaiFramework } from './frameworks/jotai'
67
import { kairoFramework } from './frameworks/kairo'
8+
import { legendFramework } from './frameworks/legend'
79
import { mobxFramework } from './frameworks/mobx'
810
import { molWireFramework } from './frameworks/molWire'
911
import { obyFramework } from './frameworks/oby'
@@ -17,10 +19,12 @@ import { xReactivityFramework } from './frameworks/xReactivity'
1719
import { zeduxFramework } from './frameworks/zedux'
1820

1921
export const frameworkInfo: FrameworkInfo[] = [
22+
// { framework: alienFramework, testPullCounts: true },
2023
// { framework: angularFramework, testPullCounts: true },
2124
// { framework: compostateFramework, testPullCounts: true },
2225
// { framework: jotaiFramework, testPullCounts: true },
2326
// { framework: kairoFramework, testPullCounts: true },
27+
// { framework: legendFramework, testPullCounts: true },
2428
// { framework: mobxFramework, testPullCounts: true },
2529
// { framework: molWireFramework, testPullCounts: true },
2630
// { framework: obyFramework, testPullCounts: true },
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Computed, Effect, endBatch, Signal, startBatch } from 'alien-signals'
2+
import { ReactiveFramework } from '../util/reactiveFramework'
3+
4+
export const alienFramework: ReactiveFramework = {
5+
name: 'alien-signals',
6+
signal: initial => {
7+
const data = new Signal(initial)
8+
return {
9+
read: () => data.get(),
10+
write: v => data.set(v),
11+
}
12+
},
13+
computed: fn => {
14+
const c = new Computed(fn)
15+
return {
16+
read: () => c.get(),
17+
}
18+
},
19+
effect: fn => new Effect(fn).run(),
20+
withBatch: fn => {
21+
startBatch()
22+
fn()
23+
endBatch()
24+
},
25+
withBuild: fn => fn(),
26+
}

bench/src/frameworks/legend.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ReactiveFramework } from '../util/reactiveFramework'
2+
import { batch, Observable, observable, observe } from '@legendapp/state'
3+
4+
export const legendFramework: ReactiveFramework = {
5+
name: 'Legend',
6+
signal: initialValue => {
7+
const s = observable(initialValue)
8+
return {
9+
write: v => (s as Observable<any>).set(v),
10+
read: () => s.get(),
11+
}
12+
},
13+
computed: <T>(fn: () => T) => {
14+
const memo = observable(fn)
15+
return {
16+
read: () => memo.get() as T,
17+
}
18+
},
19+
effect: fn => observe(fn),
20+
withBatch: fn => batch(fn),
21+
withBuild: fn => fn(),
22+
}

bench/src/frameworks/zedux.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
1-
import { Ecosystem, atom, createEcosystem } from '@zedux/atoms'
1+
import {
2+
Ecosystem,
3+
SelectorInstance,
4+
Signal,
5+
createEcosystem,
6+
} from '../../../packages/atoms' // '@zedux/atoms'
27
import { Computed, ReactiveFramework } from '../util/reactiveFramework'
38

49
let ecosystem: Ecosystem
510
let counter = 0
611

12+
class CustomSelector extends SelectorInstance {
13+
/**
14+
* Zedux cleans up graph nodes when it detects they're no longer in use. These
15+
* benchmarks don't expect that behavior. Making `node.m`aybeDestroy a noop is
16+
* all that's needed to prevent automatic destruction, while still allowing
17+
* manual destruction via `node.destroy()`.
18+
*/
19+
m() {}
20+
}
21+
722
export const zeduxFramework: ReactiveFramework = {
823
name: 'Zedux',
924
signal: initialValue => {
10-
const instance = ecosystem.getInstance(
11-
atom((counter++).toString(), initialValue)
12-
)
25+
const s = new Signal(ecosystem, (counter++).toString(), initialValue)
1326

1427
return {
15-
write: v => instance.set(v),
16-
read: () => ecosystem.live.get(instance),
28+
read: () => s.get(),
29+
write: v => s.set(v),
1730
}
1831
},
1932
computed: <T>(fn: () => T): Computed<T> => {
20-
const instance = ecosystem.getNode(fn)
33+
const s = new CustomSelector(ecosystem, (counter++).toString(), fn, [])
2134

2235
return {
23-
read: () => ecosystem.live.select(instance),
36+
read: () => s.get(),
2437
}
2538
},
2639
effect: fn => ecosystem.getNode(fn),
2740
withBatch: fn => ecosystem.batch(fn),
2841
withBuild: fn => {
29-
if (ecosystem) {
30-
ecosystem.reset()
31-
}
42+
if (ecosystem) ecosystem.reset()
43+
3244
ecosystem = createEcosystem()
45+
globalThis.ecosystem = ecosystem
3346
return fn()
3447
},
3548
}

bench/src/kairo/avoidable.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { assert } from '../util/perfLogging'
12
import { ReactiveFramework } from '../util/reactiveFramework'
23
import { busy } from './util'
34

@@ -18,12 +19,12 @@ export function avoidablePropagation(bridge: ReactiveFramework) {
1819
bridge.withBatch(() => {
1920
head.write(1)
2021
})
21-
console.assert(computed5.read() === 6)
22+
assert(computed5.read() === 6)
2223
for (let i = 0; i < 1000; i++) {
2324
bridge.withBatch(() => {
2425
head.write(i)
2526
})
26-
console.assert(computed5.read() === 6)
27+
assert(computed5.read() === 6)
2728
}
2829
}
2930
}

bench/src/kairo/broad.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
import { Counter } from "../util/dependencyGraph";
2-
import { Computed, ReactiveFramework } from "../util/reactiveFramework";
1+
import { assert } from '../util/perfLogging'
2+
import { Counter } from '../util/dependencyGraph'
3+
import { Computed, ReactiveFramework } from '../util/reactiveFramework'
34

45
/** broad propagation */
56
export function broadPropagation(bridge: ReactiveFramework) {
6-
let head = bridge.signal(0);
7-
let last = head as Computed<number>;
8-
let callCounter = new Counter();
7+
let head = bridge.signal(0)
8+
let last = head as Computed<number>
9+
let callCounter = new Counter()
910
for (let i = 0; i < 50; i++) {
1011
let current = bridge.computed(() => {
11-
return head.read() + i;
12-
});
12+
return head.read() + i
13+
})
1314
let current2 = bridge.computed(() => {
14-
return current.read() + 1;
15-
});
15+
return current.read() + 1
16+
})
1617
bridge.effect(() => {
17-
current2.read();
18-
callCounter.count++;
19-
});
20-
last = current2;
18+
current2.read()
19+
callCounter.count++
20+
})
21+
last = current2
2122
}
2223

2324
return () => {
2425
bridge.withBatch(() => {
25-
head.write(1);
26-
});
27-
const atleast = 50 * 50;
28-
callCounter.count = 0;
26+
head.write(1)
27+
})
28+
const atleast = 50 * 50
29+
callCounter.count = 0
2930
for (let i = 0; i < 50; i++) {
3031
bridge.withBatch(() => {
31-
head.write(i);
32-
});
33-
console.assert(last.read() === i + 50);
32+
head.write(i)
33+
})
34+
assert(last.read() === i + 50)
3435
}
35-
console.assert(callCounter.count === atleast, callCounter.count);
36-
};
36+
assert(callCounter.count === atleast, callCounter.count)
37+
}
3738
}

0 commit comments

Comments
 (0)