ic-mops 1.11.1 → 2.0.0
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/.DS_Store +0 -0
- package/.eslintrc.json +7 -7
- package/CHANGELOG.md +15 -0
- package/api/actors.ts +41 -37
- package/api/downloadPackageFiles.ts +75 -61
- package/api/getHighestVersion.ts +5 -5
- package/api/index.ts +4 -4
- package/api/network.ts +19 -21
- package/api/resolveVersion.ts +14 -11
- package/bin/mops.js +1 -1
- package/bun.lock +234 -198
- package/bundle/bench/bench-canister.mo +2 -2
- package/bundle/bench/user-bench.mo +0 -4
- package/bundle/bin/mops.js +1 -1
- package/bundle/cli.js +1000 -924
- package/bundle/cli.tgz +0 -0
- package/bundle/declarations/bench/bench.did +3 -3
- package/bundle/declarations/bench/bench.did.d.ts +3 -3
- package/bundle/declarations/bench/index.d.ts +3 -3
- package/bundle/declarations/bench/index.js +1 -1
- package/bundle/declarations/main/index.d.ts +3 -3
- package/bundle/declarations/main/index.js +1 -1
- package/bundle/declarations/main/main.did +78 -121
- package/bundle/declarations/main/main.did.d.ts +48 -98
- package/bundle/declarations/main/main.did.js +53 -107
- package/bundle/declarations/storage/index.d.ts +3 -3
- package/bundle/declarations/storage/index.js +4 -4
- package/bundle/declarations/storage/storage.did.d.ts +3 -3
- package/bundle/package.json +6 -5
- package/bundle/templates/mops-publish.yml +3 -3
- package/bundle/templates/mops-test.yml +3 -3
- package/bundle-package-json.ts +8 -8
- package/cache.ts +80 -65
- package/check-requirements.ts +49 -45
- package/cli.ts +577 -376
- package/commands/add.ts +142 -129
- package/commands/available-updates.ts +55 -28
- package/commands/bench/bench-canister.mo +114 -108
- package/commands/bench/user-bench.mo +6 -6
- package/commands/bench-replica.ts +146 -106
- package/commands/bench.ts +563 -497
- package/commands/build.ts +177 -0
- package/commands/bump.ts +68 -57
- package/commands/check-candid.ts +24 -0
- package/commands/docs-coverage.ts +124 -102
- package/commands/docs.ts +118 -108
- package/commands/format.ts +171 -155
- package/commands/init.ts +301 -275
- package/commands/install/install-all.ts +75 -62
- package/commands/install/install-dep.ts +43 -28
- package/commands/install/install-deps.ts +23 -15
- package/commands/install/install-local-dep.ts +42 -34
- package/commands/install/install-mops-dep.ts +154 -123
- package/commands/install/sync-local-cache.ts +39 -35
- package/commands/maintainer.ts +109 -99
- package/commands/outdated.ts +31 -18
- package/commands/owner.ts +107 -99
- package/commands/publish.ts +534 -443
- package/commands/remove.ts +119 -89
- package/commands/replica.ts +391 -303
- package/commands/search.ts +42 -36
- package/commands/self.ts +63 -56
- package/commands/sources.ts +66 -49
- package/commands/sync.ts +92 -75
- package/commands/template.ts +145 -102
- package/commands/test/mmf1.ts +146 -119
- package/commands/test/reporters/compact-reporter.ts +87 -84
- package/commands/test/reporters/files-reporter.ts +56 -51
- package/commands/test/reporters/reporter.ts +12 -6
- package/commands/test/reporters/silent-reporter.ts +58 -59
- package/commands/test/reporters/verbose-reporter.ts +66 -54
- package/commands/test/test.ts +497 -460
- package/commands/test/utils.ts +85 -6
- package/commands/toolchain/index.ts +363 -322
- package/commands/toolchain/moc.ts +78 -50
- package/commands/toolchain/pocket-ic.ts +41 -34
- package/commands/toolchain/toolchain-utils.ts +92 -72
- package/commands/toolchain/wasmtime.ts +37 -34
- package/commands/update.ts +91 -56
- package/commands/user.ts +90 -81
- package/commands/watch/deployer.ts +188 -152
- package/commands/watch/error-checker.ts +90 -80
- package/commands/watch/formatter.ts +72 -60
- package/commands/watch/generator.ts +116 -96
- package/commands/watch/globMoFiles.ts +13 -13
- package/commands/watch/parseDfxJson.ts +63 -57
- package/commands/watch/tester.ts +83 -65
- package/commands/watch/warning-checker.ts +149 -136
- package/commands/watch/watch.ts +123 -95
- package/declarations/bench/bench.did.d.ts +3 -3
- package/declarations/bench/index.d.ts +3 -3
- package/declarations/bench/index.js +1 -1
- package/declarations/main/index.d.ts +3 -3
- package/declarations/main/index.js +1 -1
- package/declarations/main/main.did.d.ts +3 -3
- package/declarations/storage/index.d.ts +3 -3
- package/declarations/storage/index.js +4 -4
- package/declarations/storage/storage.did.d.ts +3 -3
- package/dist/api/actors.d.ts +4 -4
- package/dist/api/actors.js +8 -8
- package/dist/api/downloadPackageFiles.d.ts +2 -2
- package/dist/api/downloadPackageFiles.js +10 -10
- package/dist/api/getHighestVersion.js +1 -1
- package/dist/api/index.d.ts +4 -4
- package/dist/api/index.js +4 -4
- package/dist/api/network.js +9 -9
- package/dist/api/resolveVersion.js +3 -3
- package/dist/bin/mops.js +1 -1
- package/dist/bundle-package-json.js +8 -8
- package/dist/cache.js +22 -17
- package/dist/check-requirements.js +11 -11
- package/dist/cli.js +283 -186
- package/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.js +41 -38
- package/dist/commands/available-updates.d.ts +1 -1
- package/dist/commands/available-updates.js +32 -14
- package/dist/commands/bench/bench-canister.mo +114 -108
- package/dist/commands/bench/user-bench.mo +6 -6
- package/dist/commands/bench-replica.d.ts +6 -5
- package/dist/commands/bench-replica.js +58 -36
- package/dist/commands/bench.d.ts +5 -5
- package/dist/commands/bench.js +134 -118
- package/dist/commands/build.d.ts +7 -0
- package/dist/commands/build.js +121 -0
- package/dist/commands/bump.js +27 -18
- package/dist/commands/check-candid.d.ts +4 -0
- package/dist/commands/check-candid.js +15 -0
- package/dist/commands/docs-coverage.d.ts +1 -1
- package/dist/commands/docs-coverage.js +45 -31
- package/dist/commands/docs.d.ts +1 -1
- package/dist/commands/docs.js +39 -38
- package/dist/commands/format.js +31 -27
- package/dist/commands/init.js +102 -92
- package/dist/commands/install/install-all.d.ts +2 -2
- package/dist/commands/install/install-all.js +23 -21
- package/dist/commands/install/install-dep.d.ts +1 -1
- package/dist/commands/install/install-dep.js +21 -8
- package/dist/commands/install/install-deps.d.ts +1 -1
- package/dist/commands/install/install-deps.js +1 -1
- package/dist/commands/install/install-local-dep.js +11 -9
- package/dist/commands/install/install-mops-dep.d.ts +1 -1
- package/dist/commands/install/install-mops-dep.js +32 -27
- package/dist/commands/install/sync-local-cache.js +10 -10
- package/dist/commands/maintainer.js +21 -21
- package/dist/commands/outdated.js +16 -6
- package/dist/commands/owner.js +21 -21
- package/dist/commands/publish.js +148 -128
- package/dist/commands/remove.d.ts +1 -1
- package/dist/commands/remove.js +42 -30
- package/dist/commands/replica.d.ts +9 -8
- package/dist/commands/replica.js +105 -65
- package/dist/commands/search.js +15 -13
- package/dist/commands/self.js +31 -28
- package/dist/commands/sources.d.ts +5 -1
- package/dist/commands/sources.js +23 -17
- package/dist/commands/sync.d.ts +1 -1
- package/dist/commands/sync.js +38 -25
- package/dist/commands/template.js +66 -56
- package/dist/commands/test/mmf1.d.ts +3 -3
- package/dist/commands/test/mmf1.js +33 -31
- package/dist/commands/test/reporters/compact-reporter.d.ts +3 -3
- package/dist/commands/test/reporters/compact-reporter.js +19 -15
- package/dist/commands/test/reporters/files-reporter.d.ts +3 -3
- package/dist/commands/test/reporters/files-reporter.js +18 -14
- package/dist/commands/test/reporters/reporter.d.ts +2 -2
- package/dist/commands/test/reporters/silent-reporter.d.ts +3 -3
- package/dist/commands/test/reporters/silent-reporter.js +4 -4
- package/dist/commands/test/reporters/verbose-reporter.d.ts +3 -3
- package/dist/commands/test/reporters/verbose-reporter.js +17 -13
- package/dist/commands/test/test.d.ts +4 -4
- package/dist/commands/test/test.js +151 -181
- package/dist/commands/test/utils.d.ts +6 -0
- package/dist/commands/test/utils.js +63 -2
- package/dist/commands/toolchain/index.d.ts +1 -1
- package/dist/commands/toolchain/index.js +81 -69
- package/dist/commands/toolchain/moc.d.ts +1 -1
- package/dist/commands/toolchain/moc.js +48 -24
- package/dist/commands/toolchain/pocket-ic.js +12 -12
- package/dist/commands/toolchain/toolchain-utils.d.ts +2 -0
- package/dist/commands/toolchain/toolchain-utils.js +32 -23
- package/dist/commands/toolchain/wasmtime.js +11 -11
- package/dist/commands/update.d.ts +1 -1
- package/dist/commands/update.js +30 -12
- package/dist/commands/user.js +31 -28
- package/dist/commands/watch/deployer.d.ts +4 -4
- package/dist/commands/watch/deployer.js +45 -36
- package/dist/commands/watch/error-checker.d.ts +2 -2
- package/dist/commands/watch/error-checker.js +27 -27
- package/dist/commands/watch/formatter.d.ts +4 -4
- package/dist/commands/watch/formatter.js +17 -17
- package/dist/commands/watch/generator.d.ts +3 -3
- package/dist/commands/watch/generator.js +28 -23
- package/dist/commands/watch/globMoFiles.js +8 -8
- package/dist/commands/watch/parseDfxJson.d.ts +2 -2
- package/dist/commands/watch/parseDfxJson.js +9 -9
- package/dist/commands/watch/tester.d.ts +4 -4
- package/dist/commands/watch/tester.js +23 -21
- package/dist/commands/watch/warning-checker.d.ts +3 -3
- package/dist/commands/watch/warning-checker.js +36 -36
- package/dist/commands/watch/watch.js +45 -32
- package/dist/declarations/bench/bench.did.d.ts +3 -3
- package/dist/declarations/bench/index.d.ts +3 -3
- package/dist/declarations/bench/index.js +1 -1
- package/dist/declarations/main/index.d.ts +3 -3
- package/dist/declarations/main/index.js +1 -1
- package/dist/declarations/main/main.did.d.ts +3 -3
- package/dist/declarations/storage/index.d.ts +3 -3
- package/dist/declarations/storage/index.js +4 -4
- package/dist/declarations/storage/storage.did.d.ts +3 -3
- package/dist/environments/nodejs/cli.d.ts +1 -0
- package/dist/environments/nodejs/cli.js +4 -0
- package/dist/environments/web/cli.d.ts +1 -0
- package/dist/environments/web/cli.js +4 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.js +5 -0
- package/dist/fix-dist.js +5 -5
- package/dist/helpers/find-changelog-entry.js +8 -5
- package/dist/helpers/get-dep-name.d.ts +1 -0
- package/dist/helpers/get-dep-name.js +4 -1
- package/dist/helpers/get-dfx-version.js +4 -4
- package/dist/helpers/get-moc-path.js +8 -7
- package/dist/helpers/get-moc-version.js +10 -7
- package/dist/helpers/get-package-id.js +2 -2
- package/dist/helpers/is-candid-compatible.d.ts +1 -0
- package/dist/helpers/is-candid-compatible.js +20 -0
- package/dist/integrity.d.ts +1 -1
- package/dist/integrity.js +47 -38
- package/dist/jest.config.d.ts +11 -0
- package/dist/jest.config.js +14 -0
- package/dist/mops.d.ts +6 -6
- package/dist/mops.js +87 -80
- package/dist/notify-installs.js +4 -4
- package/dist/package.json +11 -10
- package/dist/pem.d.ts +3 -3
- package/dist/pem.js +20 -12
- package/dist/release-cli.js +20 -20
- package/dist/resolve-packages.d.ts +1 -1
- package/dist/resolve-packages.js +52 -36
- package/dist/templates/mops-publish.yml +3 -3
- package/dist/templates/mops-test.yml +3 -3
- package/dist/templates/src/lib.mo +13 -13
- package/dist/templates/test/lib.test.mo +2 -2
- package/dist/templates.js +1 -1
- package/dist/tests/cli.test.d.ts +1 -0
- package/dist/tests/cli.test.js +63 -0
- package/dist/types.d.ts +14 -4
- package/dist/vessel.d.ts +2 -2
- package/dist/vessel.js +41 -34
- package/dist/wasm/pkg/bundler/package.json +20 -0
- package/dist/wasm/pkg/bundler/wasm.d.ts +3 -0
- package/dist/wasm/pkg/bundler/wasm.js +5 -0
- package/dist/wasm/pkg/bundler/wasm_bg.js +93 -0
- package/dist/wasm/pkg/bundler/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/bundler/wasm_bg.wasm.d.ts +8 -0
- package/dist/wasm/pkg/nodejs/package.json +14 -0
- package/dist/wasm/pkg/nodejs/wasm.d.ts +3 -0
- package/dist/wasm/pkg/nodejs/wasm.js +98 -0
- package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +8 -0
- package/dist/wasm/pkg/web/package.json +18 -0
- package/dist/wasm/pkg/web/wasm.d.ts +35 -0
- package/dist/wasm/pkg/web/wasm.js +191 -0
- package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/web/wasm_bg.wasm.d.ts +8 -0
- package/dist/wasm.d.ts +5 -0
- package/dist/wasm.js +10 -0
- package/environments/nodejs/cli.ts +6 -0
- package/environments/web/cli.ts +6 -0
- package/error.ts +6 -0
- package/fix-dist.ts +5 -5
- package/global.d.ts +3 -3
- package/helpers/find-changelog-entry.ts +26 -23
- package/helpers/get-dep-name.ts +7 -3
- package/helpers/get-dfx-version.ts +8 -9
- package/helpers/get-moc-path.ts +25 -26
- package/helpers/get-moc-version.ts +21 -19
- package/helpers/get-package-id.ts +4 -4
- package/helpers/is-candid-compatible.ts +22 -0
- package/integrity.ts +270 -236
- package/jest.config.js +14 -0
- package/mops.ts +238 -215
- package/notify-installs.ts +16 -17
- package/package.json +21 -15
- package/parallel.ts +28 -24
- package/pem.ts +55 -47
- package/release-cli.ts +73 -39
- package/resolve-packages.ts +231 -189
- package/templates/mops-publish.yml +3 -3
- package/templates/mops-test.yml +3 -3
- package/templates/src/lib.mo +13 -13
- package/templates/test/lib.test.mo +2 -2
- package/templates.ts +4 -4
- package/tests/__snapshots__/cli.test.ts.snap +202 -0
- package/tests/build/error/candid/bar.did +3 -0
- package/tests/build/error/dfx.json +12 -0
- package/tests/build/error/mops.toml +9 -0
- package/tests/build/error/src/Bar.mo +5 -0
- package/tests/build/error/src/Foo.mo +5 -0
- package/tests/build/success/.dfx/local/canister_ids.json +17 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.most +4 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.wasm +0 -0
- package/tests/build/success/.dfx/local/canisters/bar/constructor.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/index.js +42 -0
- package/tests/build/success/.dfx/local/canisters/bar/init_args.txt +1 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did.d.ts +7 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did.js +4 -0
- package/tests/build/success/.dfx/local/canisters/foo/constructor.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.most +4 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.wasm +0 -0
- package/tests/build/success/.dfx/local/canisters/foo/index.js +42 -0
- package/tests/build/success/.dfx/local/canisters/foo/init_args.txt +1 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did.d.ts +7 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did.js +4 -0
- package/tests/build/success/.dfx/local/lsp/ucwa4-rx777-77774-qaada-cai.did +3 -0
- package/tests/build/success/.dfx/local/lsp/ulvla-h7777-77774-qaacq-cai.did +3 -0
- package/tests/build/success/.dfx/local/network-id +4 -0
- package/tests/build/success/candid/bar.did +3 -0
- package/tests/build/success/dfx.json +12 -0
- package/tests/build/success/mops.toml +9 -0
- package/tests/build/success/src/Bar.mo +5 -0
- package/tests/build/success/src/Foo.mo +5 -0
- package/tests/check-candid/a.did +3 -0
- package/tests/check-candid/b.did +5 -0
- package/tests/check-candid/c.did +3 -0
- package/tests/cli.test.ts +82 -0
- package/tsconfig.json +26 -19
- package/types.ts +41 -31
- package/vessel.ts +219 -187
- package/wasm/Cargo.lock +1475 -0
- package/wasm/Cargo.toml +28 -0
- package/wasm/pkg/bundler/package.json +20 -0
- package/wasm/pkg/bundler/wasm.d.ts +3 -0
- package/wasm/pkg/bundler/wasm.js +5 -0
- package/wasm/pkg/bundler/wasm_bg.js +93 -0
- package/wasm/pkg/bundler/wasm_bg.wasm +0 -0
- package/wasm/pkg/bundler/wasm_bg.wasm.d.ts +8 -0
- package/wasm/pkg/nodejs/package.json +14 -0
- package/wasm/pkg/nodejs/wasm.d.ts +3 -0
- package/wasm/pkg/nodejs/wasm.js +98 -0
- package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +8 -0
- package/wasm/pkg/web/package.json +18 -0
- package/wasm/pkg/web/wasm.d.ts +35 -0
- package/wasm/pkg/web/wasm.js +191 -0
- package/wasm/pkg/web/wasm_bg.wasm +0 -0
- package/wasm/pkg/web/wasm_bg.wasm.d.ts +8 -0
- package/wasm/src/lib.rs +17 -0
- package/wasm.ts +16 -0
package/commands/bench.ts
CHANGED
|
@@ -1,527 +1,593 @@
|
|
|
1
|
-
import process from
|
|
2
|
-
import path from
|
|
3
|
-
import fs from
|
|
4
|
-
import os from
|
|
5
|
-
import chalk from
|
|
6
|
-
import {globSync} from
|
|
7
|
-
import {markdownTable} from
|
|
8
|
-
import {createLogUpdate} from
|
|
9
|
-
import {execaCommand} from
|
|
10
|
-
import stringWidth from
|
|
11
|
-
import {filesize} from
|
|
12
|
-
import terminalSize from
|
|
13
|
-
import {SemVer} from
|
|
14
|
-
|
|
15
|
-
import {getRootDir, readConfig, readDfxJson} from
|
|
16
|
-
import {parallel} from
|
|
17
|
-
import {absToRel} from
|
|
18
|
-
import {getMocVersion} from
|
|
19
|
-
import {getDfxVersion} from
|
|
20
|
-
import {getMocPath} from
|
|
21
|
-
import {sources} from
|
|
22
|
-
|
|
23
|
-
import {Benchmark, Benchmarks} from
|
|
24
|
-
import {BenchResult, _SERVICE} from
|
|
25
|
-
import {BenchReplica} from
|
|
26
|
-
|
|
27
|
-
type ReplicaName =
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { globSync } from "glob";
|
|
7
|
+
import { markdownTable } from "markdown-table";
|
|
8
|
+
import { createLogUpdate } from "log-update";
|
|
9
|
+
import { execaCommand } from "execa";
|
|
10
|
+
import stringWidth from "string-width";
|
|
11
|
+
import { filesize } from "filesize";
|
|
12
|
+
import terminalSize from "terminal-size";
|
|
13
|
+
import { SemVer } from "semver";
|
|
14
|
+
|
|
15
|
+
import { getRootDir, readConfig, readDfxJson } from "../mops.js";
|
|
16
|
+
import { parallel } from "../parallel.js";
|
|
17
|
+
import { absToRel } from "./test/utils.js";
|
|
18
|
+
import { getMocVersion } from "../helpers/get-moc-version.js";
|
|
19
|
+
import { getDfxVersion } from "../helpers/get-dfx-version.js";
|
|
20
|
+
import { getMocPath } from "../helpers/get-moc-path.js";
|
|
21
|
+
import { sources } from "./sources.js";
|
|
22
|
+
|
|
23
|
+
import { Benchmark, Benchmarks } from "../declarations/main/main.did.js";
|
|
24
|
+
import { BenchResult, _SERVICE } from "../declarations/bench/bench.did.js";
|
|
25
|
+
import { BenchReplica } from "./bench-replica.js";
|
|
26
|
+
|
|
27
|
+
type ReplicaName = "dfx" | "pocket-ic" | "dfx-pocket-ic";
|
|
28
28
|
|
|
29
29
|
let ignore = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
"**/node_modules/**",
|
|
31
|
+
"**/.mops/**",
|
|
32
|
+
"**/.vessel/**",
|
|
33
|
+
"**/.git/**",
|
|
34
34
|
];
|
|
35
35
|
|
|
36
36
|
let globConfig = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
nocase: true,
|
|
38
|
+
ignore: ignore,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
type BenchOptions = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
replica: ReplicaName;
|
|
43
|
+
replicaVersion: string;
|
|
44
|
+
compiler: "moc";
|
|
45
|
+
compilerVersion: string;
|
|
46
|
+
gc: "copying" | "compacting" | "generational" | "incremental";
|
|
47
|
+
forceGc: boolean;
|
|
48
|
+
save: boolean;
|
|
49
|
+
compare: boolean;
|
|
50
|
+
verbose: boolean;
|
|
51
|
+
silent: boolean;
|
|
52
|
+
profile: "Debug" | "Release";
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
export async function bench(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
55
|
+
export async function bench(
|
|
56
|
+
filter = "",
|
|
57
|
+
optionsArg: Partial<BenchOptions> = {},
|
|
58
|
+
): Promise<Benchmarks> {
|
|
59
|
+
let config = readConfig();
|
|
60
|
+
let dfxJson = readDfxJson();
|
|
61
|
+
|
|
62
|
+
let defaultOptions: BenchOptions = {
|
|
63
|
+
replica: config.toolchain?.["pocket-ic"] ? "pocket-ic" : "dfx",
|
|
64
|
+
replicaVersion: "",
|
|
65
|
+
compiler: "moc",
|
|
66
|
+
compilerVersion: getMocVersion(true),
|
|
67
|
+
gc: "copying",
|
|
68
|
+
forceGc: true,
|
|
69
|
+
save: false,
|
|
70
|
+
compare: false,
|
|
71
|
+
verbose: false,
|
|
72
|
+
silent: false,
|
|
73
|
+
profile: dfxJson?.profile || "Release",
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
let options: BenchOptions = { ...defaultOptions, ...optionsArg };
|
|
77
|
+
|
|
78
|
+
let replicaType =
|
|
79
|
+
options.replica ??
|
|
80
|
+
(config.toolchain?.["pocket-ic"] ? "pocket-ic" : ("dfx" as ReplicaName));
|
|
81
|
+
if (replicaType === "pocket-ic" && !config.toolchain?.["pocket-ic"]) {
|
|
82
|
+
let dfxVersion = getDfxVersion();
|
|
83
|
+
if (!dfxVersion || new SemVer(dfxVersion).compare("0.24.1") < 0) {
|
|
84
|
+
console.log(
|
|
85
|
+
chalk.red(
|
|
86
|
+
"Please update dfx to the version >=0.24.1 or specify pocket-ic version in mops.toml",
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
} else {
|
|
91
|
+
replicaType = "dfx-pocket-ic";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
options.replica = replicaType;
|
|
96
|
+
|
|
97
|
+
if (process.env.CI) {
|
|
98
|
+
console.log("# Benchmark Results\n\n");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (replicaType == "dfx") {
|
|
102
|
+
options.replicaVersion = getDfxVersion();
|
|
103
|
+
} else if (replicaType == "pocket-ic") {
|
|
104
|
+
options.replicaVersion = config.toolchain?.["pocket-ic"] || "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
options.verbose && console.log(options);
|
|
108
|
+
|
|
109
|
+
let replica = new BenchReplica(replicaType, options.verbose);
|
|
110
|
+
|
|
111
|
+
let rootDir = getRootDir();
|
|
112
|
+
let globStr = "**/bench?(mark)/**/*.bench.mo";
|
|
113
|
+
if (filter) {
|
|
114
|
+
globStr = `**/bench?(mark)/**/*${filter}*.mo`;
|
|
115
|
+
}
|
|
116
|
+
let files = globSync(path.join(rootDir, globStr), globConfig);
|
|
117
|
+
if (!files.length) {
|
|
118
|
+
if (filter) {
|
|
119
|
+
options.silent ||
|
|
120
|
+
console.log(`No benchmark files found for filter '${filter}'`);
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
if (!options.silent) {
|
|
124
|
+
console.log("No *.bench.mo files found");
|
|
125
|
+
console.log(
|
|
126
|
+
"Put your benchmark code in 'bench' directory in *.bench.mo files",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
files.sort();
|
|
133
|
+
|
|
134
|
+
let benchDir = `${getRootDir()}/.mops/.bench/`;
|
|
135
|
+
fs.rmSync(benchDir, { recursive: true, force: true });
|
|
136
|
+
fs.mkdirSync(benchDir, { recursive: true });
|
|
137
|
+
|
|
138
|
+
if (!options.silent && !process.env.CI) {
|
|
139
|
+
console.log("Benchmark files:");
|
|
140
|
+
for (let file of files) {
|
|
141
|
+
console.log(chalk.gray(`• ${absToRel(file)}`));
|
|
142
|
+
}
|
|
143
|
+
if (!process.env.CI) {
|
|
144
|
+
console.log("");
|
|
145
|
+
console.log("=".repeat(50));
|
|
146
|
+
console.log("");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
await replica.start({ silent: options.silent });
|
|
151
|
+
|
|
152
|
+
if (!process.env.CI && !options.silent) {
|
|
153
|
+
console.log("Deploying canisters...");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
await parallel(os.cpus().length, files, async (file: string) => {
|
|
157
|
+
try {
|
|
158
|
+
await deployBenchFile(file, options, replica);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error("Unexpected error. Stopping replica...");
|
|
161
|
+
await replica.stop();
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
let benchResults: Benchmarks = [];
|
|
167
|
+
|
|
168
|
+
await parallel(1, files, async (file: string) => {
|
|
169
|
+
if (!options.silent && !process.env.CI) {
|
|
170
|
+
console.log("\n" + "-".repeat(50));
|
|
171
|
+
console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
|
|
172
|
+
console.log("");
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
let benchResult = await runBenchFile(file, options, replica);
|
|
176
|
+
benchResults.push(benchResult);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
console.error("Unexpected error. Stopping replica...");
|
|
179
|
+
await replica.stop();
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (!process.env.CI && !options.silent) {
|
|
185
|
+
console.log("Stopping replica...");
|
|
186
|
+
}
|
|
187
|
+
await replica.stop();
|
|
188
|
+
|
|
189
|
+
fs.rmSync(benchDir, { recursive: true, force: true });
|
|
190
|
+
|
|
191
|
+
return benchResults;
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
function computeDiff(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
195
|
+
results: Map<string, BenchResult>,
|
|
196
|
+
prevResults: Map<string, BenchResult> | undefined,
|
|
197
|
+
rows: string[],
|
|
198
|
+
cols: string[],
|
|
199
|
+
metric: keyof BenchResult,
|
|
200
|
+
): number {
|
|
201
|
+
let diff = 0;
|
|
202
|
+
let count = 0;
|
|
203
|
+
|
|
204
|
+
for (let [_rowIndex, row] of rows.entries()) {
|
|
205
|
+
for (let [_colIndex, col] of cols.entries()) {
|
|
206
|
+
let res = results.get(`${row}:${col}`);
|
|
207
|
+
if (res && prevResults) {
|
|
208
|
+
let prevRes = prevResults.get(`${row}:${col}`);
|
|
209
|
+
if (prevRes) {
|
|
210
|
+
let denom = Number(prevRes[metric]);
|
|
211
|
+
let numerator = Number(res[metric]) - denom;
|
|
212
|
+
let percent = 0;
|
|
213
|
+
if (denom !== 0) {
|
|
214
|
+
percent = (numerator / denom) * 100;
|
|
215
|
+
}
|
|
216
|
+
if (!Number.isFinite(percent)) {
|
|
217
|
+
percent = 0;
|
|
218
|
+
}
|
|
219
|
+
diff += percent;
|
|
220
|
+
count++;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return count > 0 ? diff / count : 0;
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
function computeDiffAll(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
currentResults: Map<string, BenchResult>,
|
|
231
|
+
prevResults: Map<string, BenchResult> | undefined,
|
|
232
|
+
rows: string[],
|
|
233
|
+
cols: string[],
|
|
234
|
+
): number {
|
|
235
|
+
let metrics: (keyof BenchResult)[] = [
|
|
236
|
+
"instructions",
|
|
237
|
+
"rts_heap_size",
|
|
238
|
+
"rts_logical_stable_memory_size",
|
|
239
|
+
"rts_reclaimed",
|
|
240
|
+
];
|
|
241
|
+
let diff = 0;
|
|
242
|
+
|
|
243
|
+
for (let metric of metrics) {
|
|
244
|
+
diff += computeDiff(currentResults, prevResults, rows, cols, metric);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return diff;
|
|
235
248
|
}
|
|
236
249
|
|
|
237
|
-
function getMocArgs(options
|
|
238
|
-
|
|
250
|
+
function getMocArgs(options: BenchOptions): string {
|
|
251
|
+
let args = "";
|
|
239
252
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
if (
|
|
254
|
+
options.compilerVersion &&
|
|
255
|
+
new SemVer(options.compilerVersion).compare("0.15.0") >= 0
|
|
256
|
+
) {
|
|
257
|
+
args += " --legacy-persistence";
|
|
258
|
+
}
|
|
243
259
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
260
|
+
if (options.forceGc) {
|
|
261
|
+
args += " --force-gc";
|
|
262
|
+
}
|
|
247
263
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
264
|
+
if (options.gc) {
|
|
265
|
+
args += ` --${options.gc}-gc`;
|
|
266
|
+
}
|
|
251
267
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
268
|
+
if (options.profile === "Debug") {
|
|
269
|
+
args += " --debug";
|
|
270
|
+
} else if (options.profile === "Release") {
|
|
271
|
+
args += " --release";
|
|
272
|
+
}
|
|
258
273
|
|
|
259
|
-
|
|
274
|
+
return args;
|
|
260
275
|
}
|
|
261
276
|
|
|
262
|
-
async function deployBenchFile(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
277
|
+
async function deployBenchFile(
|
|
278
|
+
file: string,
|
|
279
|
+
options: BenchOptions,
|
|
280
|
+
replica: BenchReplica,
|
|
281
|
+
): Promise<void> {
|
|
282
|
+
let rootDir = getRootDir();
|
|
283
|
+
let tempDir = path.join(rootDir, ".mops/.bench/", path.parse(file).name);
|
|
284
|
+
let canisterName = path.parse(file).name;
|
|
285
|
+
|
|
286
|
+
// prepare temp files
|
|
287
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
288
|
+
fs.writeFileSync(
|
|
289
|
+
path.join(tempDir, "dfx.json"),
|
|
290
|
+
JSON.stringify(replica.dfxJson(canisterName), null, 2),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
let benchCanisterData = fs.readFileSync(
|
|
294
|
+
new URL("./bench/bench-canister.mo", import.meta.url),
|
|
295
|
+
"utf8",
|
|
296
|
+
);
|
|
297
|
+
benchCanisterData = benchCanisterData.replace(
|
|
298
|
+
"./user-bench",
|
|
299
|
+
path.relative(tempDir, file).replace(/.mo$/g, ""),
|
|
300
|
+
);
|
|
301
|
+
fs.writeFileSync(path.join(tempDir, "canister.mo"), benchCanisterData);
|
|
302
|
+
|
|
303
|
+
// build canister
|
|
304
|
+
let mocPath = getMocPath();
|
|
305
|
+
let mocArgs = getMocArgs(options);
|
|
306
|
+
options.verbose && console.time(`build ${canisterName}`);
|
|
307
|
+
await execaCommand(
|
|
308
|
+
`${mocPath} -c --idl canister.mo ${mocArgs} ${(await sources({ cwd: tempDir })).join(" ")}`,
|
|
309
|
+
{
|
|
310
|
+
cwd: tempDir,
|
|
311
|
+
stdio: options.verbose ? "pipe" : ["pipe", "ignore", "pipe"],
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
options.verbose && console.timeEnd(`build ${canisterName}`);
|
|
315
|
+
|
|
316
|
+
// deploy canister
|
|
317
|
+
let wasm = path.join(tempDir, "canister.wasm");
|
|
318
|
+
options.verbose && console.time(`deploy ${canisterName}`);
|
|
319
|
+
// await execaCommand(`dfx deploy ${canisterName} --mode reinstall --yes --identity anonymous`, {cwd: tempDir, stdio: options.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
320
|
+
await replica.deploy(canisterName, wasm, tempDir);
|
|
321
|
+
options.verbose && console.timeEnd(`deploy ${canisterName}`);
|
|
322
|
+
|
|
323
|
+
// init bench
|
|
324
|
+
options.verbose && console.time(`init ${canisterName}`);
|
|
325
|
+
let actor = (await replica.getActor(canisterName)) as _SERVICE;
|
|
326
|
+
await actor.init();
|
|
327
|
+
options.verbose && console.timeEnd(`init ${canisterName}`);
|
|
294
328
|
}
|
|
295
329
|
|
|
296
|
-
async function runBenchFile(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
330
|
+
async function runBenchFile(
|
|
331
|
+
file: string,
|
|
332
|
+
options: BenchOptions,
|
|
333
|
+
replica: BenchReplica,
|
|
334
|
+
): Promise<Benchmark> {
|
|
335
|
+
let rootDir = getRootDir();
|
|
336
|
+
let canisterName = path.parse(file).name;
|
|
337
|
+
|
|
338
|
+
let actor = (await replica.getActor(canisterName)) as _SERVICE;
|
|
339
|
+
let schema = await actor.getSchema();
|
|
340
|
+
|
|
341
|
+
// load previous results
|
|
342
|
+
let prevResults: Map<string, BenchResult> | undefined;
|
|
343
|
+
let resultsJsonFile = path.join(
|
|
344
|
+
rootDir,
|
|
345
|
+
".bench",
|
|
346
|
+
`${path.parse(file).name}.json`,
|
|
347
|
+
);
|
|
348
|
+
if (options.compare) {
|
|
349
|
+
if (fs.existsSync(resultsJsonFile)) {
|
|
350
|
+
let prevResultsJson = JSON.parse(
|
|
351
|
+
fs.readFileSync(resultsJsonFile).toString(),
|
|
352
|
+
);
|
|
353
|
+
prevResults = new Map(prevResultsJson.results);
|
|
354
|
+
} else {
|
|
355
|
+
console.log(
|
|
356
|
+
chalk.yellow(`No previous results found "${resultsJsonFile}"`),
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let results = new Map<string, BenchResult>();
|
|
362
|
+
|
|
363
|
+
let instructionsCells: bigint[][] = Array.from(
|
|
364
|
+
{ length: schema.rows.length },
|
|
365
|
+
() => [],
|
|
366
|
+
);
|
|
367
|
+
let heapCells: bigint[][] = Array.from(
|
|
368
|
+
{ length: schema.rows.length },
|
|
369
|
+
() => [],
|
|
370
|
+
);
|
|
371
|
+
let logicalStableMemoryCells: bigint[][] = Array.from(
|
|
372
|
+
{ length: schema.rows.length },
|
|
373
|
+
() => [],
|
|
374
|
+
);
|
|
375
|
+
let reclaimedCells: bigint[][] = Array.from(
|
|
376
|
+
{ length: schema.rows.length },
|
|
377
|
+
() => [],
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
let formatNumber = (n: bigint | number): string => {
|
|
381
|
+
return n.toLocaleString("en-US").replaceAll(",", "_");
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
let formatSize = (n: bigint | number): string => {
|
|
385
|
+
return filesize(n, { standard: "iec", round: 2 });
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
let colorizePercent = (percent: number, wrapInParens = false): string => {
|
|
389
|
+
let sign = percent > 0 ? "+" : "";
|
|
390
|
+
let percentText = percent == 0 ? "0%" : sign + percent.toFixed(2) + "%";
|
|
391
|
+
let color: keyof typeof chalk =
|
|
392
|
+
percent == 0 ? "gray" : percent > 0 ? "red" : "green";
|
|
393
|
+
let parens = wrapInParens ? ["(", ")"] : ["", ""];
|
|
394
|
+
if (process.env.CI) {
|
|
395
|
+
return `$${parens[0]}{\\color{${color}}${percentText.replace("%", "\\\\%")}}${parens[1]}$`;
|
|
396
|
+
} else {
|
|
397
|
+
return `${parens[0]}${chalk[color](percentText)}${parens[1]}`;
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
let getTable = (prop: keyof BenchResult): string => {
|
|
402
|
+
let resArr = [["", ...schema.cols]];
|
|
403
|
+
let allZero = true;
|
|
404
|
+
|
|
405
|
+
for (let [_rowIndex, row] of schema.rows.entries()) {
|
|
406
|
+
let curRow = [row];
|
|
407
|
+
|
|
408
|
+
for (let [_colIndex, col] of schema.cols.entries()) {
|
|
409
|
+
let res = results.get(`${row}:${col}`);
|
|
410
|
+
if (res) {
|
|
411
|
+
if (res[prop] != 0n) {
|
|
412
|
+
allZero = false;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// compare with previous results
|
|
416
|
+
let diff = "";
|
|
417
|
+
if (options.compare && prevResults) {
|
|
418
|
+
let prevRes = prevResults.get(`${row}:${col}`);
|
|
419
|
+
if (prevRes) {
|
|
420
|
+
let percent =
|
|
421
|
+
((Number(res[prop]) - Number(prevRes[prop])) /
|
|
422
|
+
Number(prevRes[prop])) *
|
|
423
|
+
100;
|
|
424
|
+
if (Object.is(percent, NaN)) {
|
|
425
|
+
percent = 0;
|
|
426
|
+
}
|
|
427
|
+
diff = " " + colorizePercent(percent, true);
|
|
428
|
+
} else {
|
|
429
|
+
diff = chalk.yellow(" (no previous results)");
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// add to table
|
|
434
|
+
let value = "";
|
|
435
|
+
if (prop == "rts_logical_stable_memory_size") {
|
|
436
|
+
value = formatSize(res[prop] * 65536n);
|
|
437
|
+
} else if (prop === "rts_heap_size" || prop == "rts_reclaimed") {
|
|
438
|
+
value = formatSize(res[prop]);
|
|
439
|
+
} else {
|
|
440
|
+
value = formatNumber(res[prop]);
|
|
441
|
+
}
|
|
442
|
+
curRow.push(value + diff);
|
|
443
|
+
} else {
|
|
444
|
+
curRow.push("");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
resArr.push(curRow);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// don't show Stable Memory table if all values are 0
|
|
451
|
+
if (allZero && prop == "rts_logical_stable_memory_size") {
|
|
452
|
+
return "";
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return markdownTable(resArr, {
|
|
456
|
+
align: ["l", ..."r".repeat(schema.cols.length)],
|
|
457
|
+
stringLength: stringWidth,
|
|
458
|
+
});
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
|
|
462
|
+
|
|
463
|
+
let getOutput = () => {
|
|
464
|
+
if (process.env.CI) {
|
|
465
|
+
return [
|
|
466
|
+
"\n<details>",
|
|
467
|
+
`\n<summary>${absToRel(file)} ${colorizePercent(computeDiffAll(results, prevResults, schema.rows, schema.cols), true).replace("\\\\%", "\\%")}</summary>`,
|
|
468
|
+
`\n${process.env.CI ? `### ${schema.name}` : chalk.bold(schema.name)}`,
|
|
469
|
+
`${schema.description ? "\n" + (process.env.CI ? `_${schema.description}_` : chalk.gray(schema.description)) : ""}`,
|
|
470
|
+
`\n\nInstructions: ${colorizePercent(computeDiff(results, prevResults, schema.rows, schema.cols, "instructions"), false)}`,
|
|
471
|
+
`Heap: ${colorizePercent(computeDiff(results, prevResults, schema.rows, schema.cols, "rts_heap_size"), false)}`,
|
|
472
|
+
`Stable Memory: ${colorizePercent(computeDiff(results, prevResults, schema.rows, schema.cols, "rts_logical_stable_memory_size"), false)}`,
|
|
473
|
+
`Garbage Collection: ${colorizePercent(computeDiff(results, prevResults, schema.rows, schema.cols, "rts_reclaimed"), false)}`,
|
|
474
|
+
`\n\n**Instructions**\n\n${getTable("instructions")}`,
|
|
475
|
+
`\n\n**Heap**\n\n${getTable("rts_heap_size")}`,
|
|
476
|
+
`\n\n**Garbage Collection**\n\n${getTable("rts_reclaimed")}`,
|
|
477
|
+
`${getTable("rts_logical_stable_memory_size") ? `\n\n**Stable Memory**\n\n${getTable("rts_logical_stable_memory_size")}` : ""}`,
|
|
478
|
+
"\n</details>",
|
|
479
|
+
].join("\n");
|
|
480
|
+
} else {
|
|
481
|
+
return `
|
|
427
482
|
\n${chalk.bold(schema.name)}
|
|
428
|
-
${schema.description ?
|
|
429
|
-
\n\n${chalk.blue(
|
|
430
|
-
\n\n${chalk.blue(
|
|
431
|
-
\n\n${chalk.blue(
|
|
432
|
-
${getTable(
|
|
483
|
+
${schema.description ? "\n" + chalk.gray(schema.description) : ""}
|
|
484
|
+
\n\n${chalk.blue("Instructions")}\n\n${getTable("instructions")}
|
|
485
|
+
\n\n${chalk.blue("Heap")}\n\n${getTable("rts_heap_size")}
|
|
486
|
+
\n\n${chalk.blue("Garbage Collection")}\n\n${getTable("rts_reclaimed")}
|
|
487
|
+
${getTable("rts_logical_stable_memory_size") ? `\n\n${chalk.blue("Stable Memory")}\n\n${getTable("rts_logical_stable_memory_size")}` : ""}
|
|
433
488
|
`;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
let canUpdateLog =
|
|
493
|
+
!process.env.CI &&
|
|
494
|
+
!options.silent &&
|
|
495
|
+
terminalSize().rows > getOutput().split("\n").length;
|
|
496
|
+
|
|
497
|
+
let log = () => {
|
|
498
|
+
if (options.silent) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
let output = getOutput();
|
|
502
|
+
if (process.env.CI || terminalSize().rows <= output.split("\n").length) {
|
|
503
|
+
console.log(output);
|
|
504
|
+
} else {
|
|
505
|
+
logUpdate(output);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
if (canUpdateLog) {
|
|
510
|
+
log();
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// run all cells
|
|
514
|
+
for (let [rowIndex, row] of schema.rows.entries()) {
|
|
515
|
+
for (let [colIndex, col] of schema.cols.entries()) {
|
|
516
|
+
let res = await actor.runCellUpdateAwait(
|
|
517
|
+
BigInt(rowIndex),
|
|
518
|
+
BigInt(colIndex),
|
|
519
|
+
);
|
|
520
|
+
results.set(`${row}:${col}`, res);
|
|
521
|
+
|
|
522
|
+
// @ts-ignore
|
|
523
|
+
instructionsCells[rowIndex][colIndex] = res.instructions;
|
|
524
|
+
// @ts-ignore
|
|
525
|
+
heapCells[rowIndex][colIndex] = res.rts_heap_size;
|
|
526
|
+
// @ts-ignore
|
|
527
|
+
logicalStableMemoryCells[rowIndex][colIndex] =
|
|
528
|
+
res.rts_logical_stable_memory_size;
|
|
529
|
+
// @ts-ignore
|
|
530
|
+
reclaimedCells[rowIndex][colIndex] = res.rts_reclaimed;
|
|
531
|
+
|
|
532
|
+
if (canUpdateLog) {
|
|
533
|
+
log();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (canUpdateLog) {
|
|
539
|
+
logUpdate.done();
|
|
540
|
+
} else {
|
|
541
|
+
log();
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// save results
|
|
545
|
+
if (options.save) {
|
|
546
|
+
console.log(`Saving results to ${chalk.gray(absToRel(resultsJsonFile))}`);
|
|
547
|
+
let json: Record<any, any> = {
|
|
548
|
+
version: 1,
|
|
549
|
+
moc: options.compilerVersion,
|
|
550
|
+
replica: options.replica,
|
|
551
|
+
replicaVersion: options.replicaVersion,
|
|
552
|
+
gc: options.gc,
|
|
553
|
+
forceGc: options.forceGc,
|
|
554
|
+
results: Array.from(results.entries()),
|
|
555
|
+
};
|
|
556
|
+
fs.mkdirSync(path.dirname(resultsJsonFile), { recursive: true });
|
|
557
|
+
fs.writeFileSync(
|
|
558
|
+
resultsJsonFile,
|
|
559
|
+
JSON.stringify(
|
|
560
|
+
json,
|
|
561
|
+
(_, val) => {
|
|
562
|
+
if (typeof val === "bigint") {
|
|
563
|
+
return Number(val);
|
|
564
|
+
} else {
|
|
565
|
+
return val;
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
2,
|
|
569
|
+
),
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// for backend
|
|
574
|
+
return {
|
|
575
|
+
name: schema.name,
|
|
576
|
+
description: schema.description,
|
|
577
|
+
file: absToRel(file),
|
|
578
|
+
gc: options.gc,
|
|
579
|
+
forceGC: options.forceGc,
|
|
580
|
+
replica: options.replica,
|
|
581
|
+
replicaVersion: options.replicaVersion,
|
|
582
|
+
compiler: options.compiler,
|
|
583
|
+
compilerVersion: options.compilerVersion,
|
|
584
|
+
rows: schema.rows,
|
|
585
|
+
cols: schema.cols,
|
|
586
|
+
metrics: [
|
|
587
|
+
["instructions", instructionsCells],
|
|
588
|
+
["rts_heap_size", heapCells],
|
|
589
|
+
["rts_logical_stable_memory_size", logicalStableMemoryCells],
|
|
590
|
+
["rts_reclaimed", reclaimedCells],
|
|
591
|
+
],
|
|
592
|
+
};
|
|
527
593
|
}
|