Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/assets/banner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions .github/drop-ins.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@
"theirs": 6.977973875000316,
"ours": 0.5743697890625299
}
},
{
"package": "tinylinkify",
"library": "linkify-it 5.0.2",
"entry": "tinylinkify/linkify-it",
"gzip": {
"theirs": 4211,
"ours": 3998
},
"parse": {
"theirs": 5.928683062499999,
"ours": 5.55748618749999
},
"machine": "AMD Ryzen 7 255 w/ Radeon 780M Graphics, Node 24.21.0"
}
],
"root": {
Expand Down Expand Up @@ -335,6 +349,20 @@
"theirs": 1.5631965937500354,
"ours": 0.44089388281247466
}
},
{
"package": "tinylinkify",
"library": "linkify-it 5.0.2",
"entry": "tinylinkify",
"gzip": {
"theirs": 4211,
"ours": 1836
},
"parse": {
"theirs": 5.666320437499962,
"ours": 2.022400906250141
},
"machine": "AMD Ryzen 7 255 w/ Radeon 780M Graphics, Node 24.21.0"
}
]
}
15 changes: 13 additions & 2 deletions .github/scripts/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ${b.stats
</svg>
`;

const { dropIns, root } = readDropIns();
const { dropIns, root, roots = [] } = readDropIns();
const row = (library: string) => dropIns.find((r) => r.library === library)!;
const count = (pkg: string) => String(dropIns.filter((r) => r.package === pkg).length);
const dependencies = (pkg: string) =>
Expand All @@ -89,7 +89,7 @@ const banners: Banner[] = [
{
file: ".github/assets/banner.svg",
name: "tiny",
title: "tiny: smaller, faster drop-ins for YAML, JSON5, JSONC and INI libraries",
title: "tiny: smaller, faster drop-ins for YAML, JSON5, JSONC and INI libraries, and linkify-it",
tagline: "Smaller, faster parsers. Same API.",
stats: [
[String(dropIns.length), "drop-in replacements"],
Expand Down Expand Up @@ -131,6 +131,17 @@ const banners: Banner[] = [
[dependencies("tinyini"), "dependencies"],
],
},
{
file: "packages/tinylinkify/.github/banner.svg",
name: "tinylinkify",
title: "tinylinkify: GFM links in text, and a smaller, faster drop-in for linkify-it 5",
tagline: "GFM links in text, and a faster linkify-it.",
stats: [
[`${kib(roots.find((r) => r.entry === "tinylinkify")!.gzip.ours)} KiB`, "own API, gzipped"],
[times(roots.find((r) => r.entry === "tinylinkify")!.parse), "faster than linkify-it"],
[dependencies("tinylinkify"), "dependencies"],
],
},
];

const write = (file: string, content: string | Buffer) => {
Expand Down
85 changes: 66 additions & 19 deletions .github/scripts/drop-ins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
// package's large benchmark file. The numbers come from each package's own
// scripts/size.ts and bench/index.ts, run with --json. automd.config.ts turns
// the file into the tables in the READMEs.
// Usage: node --no-warnings .github/scripts/drop-ins.ts
// Name packages to measure only theirs: the other rows stay as they are, and
// rows measured on another machine than the file's say which.
// Usage: node --no-warnings .github/scripts/drop-ins.ts [package...]
import { execFileSync } from "node:child_process";
import { writeFileSync } from "node:fs";
import { existsSync, writeFileSync } from "node:fs";
import { cpus } from "node:os";
import type { Comparison, DropIns } from "../../automd.config.ts";
import { readDropIns, type Comparison, type DropIns } from "../../automd.config.ts";

const only = process.argv.slice(2);
const measure = (pkg: string) => !only.length || only.includes(pkg);
const previous = existsSync(".github/drop-ins.json") ? readDropIns() : undefined;
const machine = `${cpus()[0]!.model.trim()}, Node ${process.versions.node}`;

// A script may log a build first, so the JSON starts at the first line that is
// only "{" or "[".
Expand All @@ -23,12 +30,13 @@ const run = (pkg: string, script: string) => {
type Sizes = Record<string, { gzip: number }>;
type Rows = { operation: string; theirs: number; ours?: number; tinyaml?: number; library?: string }[];

const yamlSize: Sizes = run("tinyaml", "scripts/size.ts");
const yamlBench: Rows = run("tinyaml", "bench/index.ts");
const json5Size: Sizes = run("tinyjson5", "scripts/size.ts");
const json5Bench: Rows = run("tinyjson5", "bench/index.ts");
const iniSize: Sizes = run("tinyini", "scripts/size.ts");
const iniBench: Rows = run("tinyini", "bench/index.ts");
// A package's sizes and timings, or nothing when it isn't being measured.
const numbers = (pkg: string): [Sizes, Rows] =>
measure(pkg) ? [run(pkg, "scripts/size.ts"), run(pkg, "bench/index.ts")] : [{}, []];
const [yamlSize, yamlBench] = numbers("tinyaml");
const [json5Size, json5Bench] = numbers("tinyjson5");
const [iniSize, iniBench] = numbers("tinyini");
const [linkSize, linkBench] = numbers("tinylinkify");

const timing = (rows: Rows, operation: string, library?: string) => {
const r = rows.find((r) => r.operation === operation && (!library || r.library === library));
Expand All @@ -42,22 +50,34 @@ const compare = (
[theirs, ours]: [string, string],
rows: Rows,
benchLibrary?: string,
): Comparison => ({
package: pkg,
library,
entry,
gzip: { theirs: sizes[theirs]!.gzip, ours: sizes[ours]!.gzip },
parse: timing(rows, "parse large", benchLibrary)!,
// A library that only parses, such as strip-json-comments, has no stringify row.
stringify: timing(rows, "stringify large", benchLibrary),
});
// What "parse" is for this package's bench: linkify-it's is `match`.
parse = "parse large",
): Comparison => {
if (!measure(pkg)) {
const kept = [...(previous?.dropIns ?? []), previous?.root, ...(previous?.roots ?? [])].find(
(r) => r?.entry === entry && r.library === library,
);
if (!kept) throw new Error(`${entry} has no row in .github/drop-ins.json; measure ${pkg}`);
return { ...kept, machine: kept.machine ?? previous!.machine };
}
return {
package: pkg,
library,
entry,
gzip: { theirs: sizes[theirs]!.gzip, ours: sizes[ours]!.gzip },
parse: timing(rows, parse, benchLibrary)!,
// A library that only parses, such as strip-json-comments, has no stringify row.
stringify: timing(rows, "stringify large", benchLibrary),
machine,
};
};
const yaml = (library: string, entry: string, size: string, bench: string) =>
compare("tinyaml", library, entry, yamlSize, [size, entry], yamlBench, bench);
const ini = (library: string, entry: string, bench = library) =>
compare("tinyini", library, entry, iniSize, [library, entry], iniBench, bench);

const data: DropIns = {
machine: `${cpus()[0]!.model.trim()}, Node ${process.versions.node}`,
machine,
dropIns: [
yaml("js-yaml 4", "tinyaml/js-yaml", "js-yaml 4", "js-yaml"),
yaml("js-yaml 5", "tinyaml/js-yaml-v5", "js-yaml 5", "js-yaml 5"),
Expand All @@ -84,6 +104,16 @@ const data: DropIns = {
ini("ini 1.3.8", "tinyini/ini-v1"),
ini("@one-ini/wasm 0.2.1", "tinyini/one-ini"),
ini("@one-ini/wasm 0.1.1", "tinyini/one-ini-v0.1"),
compare(
"tinylinkify",
"linkify-it 5.0.2",
"tinylinkify/linkify-it",
linkSize,
["linkify-it 5.0.2", "tinylinkify/linkify-it"],
linkBench,
"linkify-it 5.0.2",
"match large",
),
],
root: yaml("yaml 2", "tinyaml", "yaml", "yaml (tinyaml root)"),
// The other packages' own APIs, each against the library its users switch from.
Expand All @@ -98,8 +128,25 @@ const data: DropIns = {
"json5 2.2.3 (tinyjson5 root)",
),
ini("ini 7.0.0", "tinyini", "ini 7.0.0 (tinyini root)"),
compare(
"tinylinkify",
"linkify-it 5.0.2",
"tinylinkify",
linkSize,
["linkify-it 5.0.2", "tinylinkify"],
linkBench,
"linkify-it 5.0.2 (tinylinkify root)",
"match large",
),
],
};
// The file's machine is the one most rows were measured on; rows from it
// don't repeat it.
const rows = [...data.dropIns, data.root, ...data.roots!];
const tally = new Map<string, number>();
for (const r of rows) tally.set(r.machine!, (tally.get(r.machine!) ?? 0) + 1);
data.machine = [...tally].sort((a, b) => b[1] - a[1])[0]![0];
for (const r of rows) if (r.machine === data.machine) delete r.machine;

writeFileSync(".github/drop-ins.json", `${JSON.stringify(data, null, 2)}\n`);
console.log(".github/drop-ins.json");
Loading
Loading