blob: f82e0b8628551600b246c70ba948b8aeb428784c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
(* Cache Solid Pill - Cue once and save marshalled OCaml noun
*
* This cues the solid pill once (slow) and saves the resulting
* noun using OCaml's Marshal for fast loading later
*)
open Nock_lib
let cache_solid env =
Printf.printf "Caching solid pill...\n\n";
Eio.Switch.run @@ fun _sw ->
let fs = Eio.Stdenv.fs env in
(* Load and cue solid pill *)
Printf.printf "Step 1: Loading solid.pill (8.7 MB)...\n";
let file_path = Eio.Path.(fs / "solid.pill") in
let pill_bytes = Eio.Path.load file_path |> Bytes.of_string in
Printf.printf " Loaded %d bytes\n\n" (Bytes.length pill_bytes);
Printf.printf "Step 2: Cuing (this will take several minutes)...\n";
let start = Unix.gettimeofday () in
let pill = Serial.cue pill_bytes in
let elapsed = Unix.gettimeofday () -. start in
Printf.printf " ✓ Cued in %.1fs\n\n" elapsed;
Printf.printf "Step 3: Marshalling noun to solid.noun...\n";
let out_channel = open_out_bin "solid.noun" in
Marshal.to_channel out_channel pill [];
close_out out_channel;
Printf.printf " ✓ Saved to solid.noun\n\n";
Printf.printf "Step 4: Testing reload speed...\n";
let start = Unix.gettimeofday () in
let in_channel = open_in_bin "solid.noun" in
let _reloaded = (Marshal.from_channel in_channel : Noun.noun) in
close_in in_channel;
let elapsed = Unix.gettimeofday () -. start in
Printf.printf " ✓ Reloaded in %.4fs (much faster!)\n\n" elapsed;
Printf.printf "Done! Use solid.noun for fast testing.\n"
let () = Eio_main.run cache_solid
|