Cotton code
46 lines · 2.1 KB · TypeScriptRaw
/** * THE THREE CRATES A DEBUG BUILD COMPILES OPTIMISED — AND ONLY THOSE THREE. * * `crates/Cargo.toml` builds `scrypt`, `salsa20` and `libsqlite3-sys` at * `opt-level = 3` even in a debug or test build, each for a measured reason * written beside it there: * *   scrypt, salsa20   ~480 of 4,475 test-seconds were one unoptimised scrypt *                     loop (run 181). *   libsqlite3-sys    every test opens a real SQLite file; the amalgamation at *                     opt-level 0 cost `cotton-store` + `cotton-tools` 37% more *                     wall time (806/788 s vs 530/467 s, 28 Sep 2026), inside *                     the `rust` check job's 10–11-minute test run. * * Dropping one of them silently puts minutes back on every pull request's * slowest check, so it fails here. And NOT `profile.dev.package."*"`: a blanket * override re-optimises five hundred dependencies and lengthens every cold * build for wins that live in three leaves — that fails here too. */import { readFileSync } from "node:fs";import { join } from "node:path";import { describe, expect, it } from "vitest";const MANIFEST = readFileSync(join(__dirname, "..", "..", "crates", "Cargo.toml"), "utf8");function optLevel(pkg: string): string | undefined {  const escaped = pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");  const block = MANIFEST.match(new RegExp(`^\\[profile\\.dev\\.package\\.${escaped}\\]\\n([^\\[]*)`, "m"));  return block?.[1].match(/^opt-level\s*=\s*(\S+)/m)?.[1];}describe("crates/Cargo.toml — what a debug build compiles optimised", () => {  it.each(["scrypt", "salsa20", "libsqlite3-sys"])("builds %s at opt-level 3 in a debug and test build", (pkg) => {    expect(optLevel(pkg)).toBe("3");  });  it("never optimises every dependency at once", () => {    expect(MANIFEST).not.toMatch(/^\[profile\.dev\.package\."\*"\]/m);  });  it("SQLite is the bundled amalgamation, so the flag reaches the C code", () => {    // Without `bundled`, SQLite would be the system library and the override    // would optimise nothing — the measurement above would not hold.    expect(MANIFEST).toMatch(/^rusqlite = \{[^}]*"bundled"/m);  });});