You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bab655e
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,14 +61,14 @@ deno lint js/
61
61
62
62
### Bench
63
63
64
-
`cargo run -p bench --profile cli` runs every case of `vm.json` on the `cargo wasm-cli` build, and stops when that build is older than `src/`. It counts the WebAssembly instructions each case executes and prices each at 0.82 ns, the 822756 gas that `wasm_regular_op_cost` sets in `core/parameters/res/runtime_configs/parameters.yaml` of nearcore, at the 1 ms per Tgas its gas estimator budgets, so `bench/.snapshot` keeps reference seconds that come out the same on every machine. Each case keeps them beside its memory peak in MB, by the model the memory limit counts, as `[seconds, MB]`.
64
+
`cargo run -p bench --profile cli` runs every case of `vm.json` on the `cargo wasm-cli` build, and stops when that build is older than `src/`. It counts the WebAssembly instructions each case executes and prices each at 0.82 ns, the 822756 gas that `wasm_regular_op_cost` sets in `core/parameters/res/runtime_configs/parameters.yaml` of nearcore, at the 1 ms per Tgas its gas estimator budgets, so `bench/.snapshot` keeps reference seconds that come out the same on every machine. Each case keeps them beside its memory peak in MB, by the model the memory limit counts, as `[seconds, MB]`. The peak includes garbage not yet collected, so a change to when the collector runs moves it too.
65
65
66
66
The Bench job fails a pull request when
67
67
68
68
- the snapshot was taken with another Rust,
69
69
- a case is missing from it, or an entry has no case,
70
70
- the geometric mean of time or memory moves past its threshold, either way,
71
-
- a single case moves past its own threshold in either.
71
+
- a single case moves past its own threshold in either, and in memory also by more than `memory_floor` MB.
72
72
73
73
Every run prints how the cases already in the snapshot moved, even when another rule fails. `--update` reports the change and takes the snapshot again, and a faster engine takes it too, so the next change is measured from where the code stands.
constMEMORY:Measure = Measure{pick: |c| c.1,unit:"MB",places:6,grew:"holds more memory",shrank:"holds less memory",most_grown:"Most grown",most_shrunk:"Biggest drops",own:" in memory",total:("peaks at","summed over its cases")};
constMEMORY:Measure = Measure{pick: |c| c.1,floor: |s| s.memory_floor,unit:"MB",places:6,grew:"holds more memory",shrank:"holds less memory",most_grown:"Most grown",most_shrunk:"Biggest drops",own:" in memory",total:("peaks at","summed over its cases")};
43
46
44
47
fnmain(){
45
48
let update = std::env::args().any(|a| a == "--update");
@@ -60,17 +63,28 @@ fn main() {
60
63
let ran:Vec<(String,(u64,u64))> = cases.iter().map(|case| (key(case),run(&engine,&module, case))).collect();
let rustc = Command::new("rustc").arg("--version").current_dir(ROOT).output().map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()).unwrap_or_default();
63
-
let now = Snapshot{ rustc,threshold:0.005,case_threshold:0.05,cases: measured };
66
+
let now = Snapshot{ rustc,threshold:0.005,case_threshold:0.05,memory_floor:0.004,cases: measured };
64
67
let sources:BTreeMap<String,&str> = cases.iter().map(|c| (key(c), c["src"].as_str().unwrap_or(""))).collect();
65
68
66
-
let last = std::fs::read_to_string(SNAPSHOT).ok().and_then(|s| serde_json::from_str::<Snapshot>(&s).ok());
69
+
// Only a missing snapshot is taken without comparing, one that does not parse fails unless --update replaces it.
70
+
let last = match std::fs::read_to_string(SNAPSHOT){
71
+
Err(_) => None,
72
+
Ok(text) => match serde_json::from_str::<Snapshot>(&text){
73
+
Ok(snapshot) => Some(snapshot),
74
+
Err(_)if update => None,
75
+
Err(e) => {
76
+
annotate("error",&format!("bench/.snapshot does not parse, {e}, take it again with --update."));
77
+
std::process::exit(1);
78
+
}
79
+
},
80
+
};
67
81
let failures = last.as_ref().map(|l| check(l,&now,&sources)).unwrap_or_default();
let all:Vec<(&String,f64,f64)> = now.cases.iter().filter_map(|(k,&n)| last.cases.get(k).map(|&l| (k,(m.pick)(l),(m.pick)(n)))).collect();
102
117
// Every case weighs the same in a geometric mean, so no single long case decides it.
103
-
let paired:Vec<(&String,f64,f64)> = now.cases.iter().filter_map(|(k,&n)| last.cases.get(k).map(|&l| (k,(m.pick)(l),(m.pick)(n)))).filter(|&(_, l, n)| l > 0.0 && n > 0.0).collect();
118
+
let paired:Vec<(&String,f64,f64)> = all.iter().copied().filter(|&(_, l, n)| l > 0.0 && n > 0.0).collect();
failures.push(format!("vm.json {}, {total:.3} {unit} against {before:.3} {unit}, {:+.2}%. The snapshot no longer matches the code, run --update and commit it with the change. {}{}", m.shrank, change *100.0, m.most_shrunk, list(&moved(false))));
Copy file name to clipboardExpand all lines: docs/03-reference/06-abi.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -446,7 +446,7 @@ Distinct from the sealed plugin imports above, these are exports on `compiler.wa
446
446
|---|---|---|
447
447
|`set_limits`|`(memory: u64, ops: u64)`| Caps for the next `run_start` or `repl_eval`, memory in bytes. A zero field keeps the sandbox value. `restore_state` keeps the limits embedded in the blob. |
448
448
|`set_entry`|`(ptr: *const u8, len: u32)`| Name the script the next run starts from. Tracebacks name its frame after it, and its directory roots the walk and the relative imports of the program. An empty entry, or a directory ending in `/`, runs from that directory and renders its frame as `<input>`. |
449
-
|`memory_peak`|`() -> u64`| The most the last run held at once, in bytes, by the memory model the limit counts. |
449
+
|`memory_peak`|`() -> u64`| The most the last run held at once, in bytes, by the memory model the limit counts, garbage not yet collected included. A run that fails to compile reads 0. |
450
450
|`save_state`|`() -> i64`| Serialise the parked run into the out buffer. Returns the blob length, or `-1` when nothing is parked. |
451
451
|`restore_state`|`(ptr: *const u8, len: u32) -> u32`| Boot a VM from the blob at `ptr` and overlay its state. Returns the same packed status word as `run_start`. |
452
452
|`state_globals`|`() -> u32`| Write the parked run's module-level bindings as JSON into the out buffer. Returns its byte length. |
0 commit comments