Something went wrong. Try again.
Neovim Statusline
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160local source = debug.getinfo(1, "S").source:sub(2)local root = vim.fn.fnamemodify(source, ":p:h:h")local benchmark = dofile(vim.fs.joinpath(root, "benchmarks", "lib.lua"))
local function main() local quick = benchmark.env_truthy("STATUSLINE_BENCH_QUICK") local samples = benchmark.positive_integer("STATUSLINE_BENCH_STARTUP_SAMPLES", quick and 3 or 15) local warmup = benchmark.positive_integer("STATUSLINE_BENCH_STARTUP_WARMUP", quick and 1 or 3) local startup_init = vim.fs.joinpath(root, "benchmarks", "startup_init.lua") local nvim = vim.env.NVIM_BIN or vim.v.progpath
local function run_child(load_plugin) local profile = vim.fn.tempname() local completed = vim.system({ nvim, "--headless", "--clean", "-i", "NONE", "--startuptime", profile, "-u", startup_init, "+qa!", }, { text = true, env = { STATUSLINE_BENCH_LOAD_PLUGIN = load_plugin and "1" or "0", }, }):wait()
if completed.code ~= 0 then vim.fn.delete(profile) error( ("startup child failed with exit code %d\nstdout:\n%s\nstderr:\n%s"):format( completed.code, completed.stdout or "", completed.stderr or "" ) ) end
local lines = vim.fn.readfile(profile) vim.fn.delete(profile) for index = #lines, 1, -1 do local elapsed = lines[index]:match("^([%d.]+).+NVIM STARTED") if elapsed then return assert(tonumber(elapsed)) end end
error("could not find the NVIM STARTED marker in the startup profile") end
local function run_pair(baseline_first) if baseline_first then return run_child(false), run_child(true) end local plugin = run_child(true) return run_child(false), plugin end
for index = 1, warmup do run_pair(index % 2 == 1) end
local baseline_samples = {} local plugin_samples = {} local paired_deltas = {} for index = 1, samples do local baseline, plugin = run_pair(index % 2 == 1) baseline_samples[index] = baseline plugin_samples[index] = plugin paired_deltas[index] = plugin - baseline end
local baseline = benchmark.summarize(baseline_samples) local plugin = benchmark.summarize(plugin_samples) local delta = benchmark.summarize(paired_deltas) local ratio = plugin.median / baseline.median local percent = (plugin.median - baseline.median) / baseline.median * 100
local configuration = { quick = quick, samples = samples, warmup_pairs = warmup, child_nvim = nvim, } local report = { schema_version = 1, kind = "statusline.nvim-startup", metadata = benchmark.metadata(root, configuration), baseline = { description = "Benchmark init with runtime path and dependency stub only", unit = "ms", samples_ms = baseline_samples, stats = baseline, }, plugin = { description = "Same init plus require('statusline').setup()", unit = "ms", samples_ms = plugin_samples, stats = plugin, }, impact = { method = "paired plugin minus baseline startup time", unit = "ms", samples_ms = paired_deltas, stats = delta, ratio_of_medians = ratio, percent_of_medians = percent, }, notes = { "Times come from Neovim's --startuptime NVIM STARTED marker, not parent-process wall time.", "Baseline and plugin children are paired and their execution order alternates.", "The dependency is a deterministic in-memory stub in both child configurations.", }, }
local function format_statistics(label, statistics) return string.format( "%-20s %11s %11s %11s %11s", label, benchmark.format_duration(statistics.median * 1e6), benchmark.format_duration(statistics.p95 * 1e6), benchmark.format_duration(statistics.min * 1e6), benchmark.format_duration(statistics.max * 1e6) ) end
local lines = { "statusline.nvim startup benchmarks", ("Neovim %s | %s | %s"):format( report.metadata.neovim, report.metadata.lua, report.metadata.cpu.model ), ("samples=%d warmup_pairs=%d (fresh Neovim process per observation)"):format(samples, warmup), "", string.format("%-20s %11s %11s %11s %11s", "measurement", "median", "p95", "min", "max"), string.rep("-", 68), format_statistics("baseline startup", baseline), format_statistics("plugin startup", plugin), format_statistics("paired impact", delta), "", ("Impact from medians: %.2fx, %+.1f%%"):format(ratio, percent), "Run on an idle machine and compare several repetitions; process startup is inherently noisy.", }
benchmark.write_report(report, table.concat(lines, "\n"), "STATUSLINE_BENCH_STARTUP_OUTPUT")end
local ok, err = xpcall(main, debug.traceback)if not ok then vim.api.nvim_err_writeln(err) vim.cmd("cquit 1")else vim.cmd("qa!")end