Skip to content

perf(markdown-formatter): unwired producer builds telemetry payload before the opt-in guard (~90ms/edit on Windows) #6

Description

@kyle-sexton

Summary

When HOOK_TELEMETRY_SINK is unset (telemetry not wired — the default for consumers who have not opted in), the markdown-format producer still performs telemetry-only work before the opt-in guard short-circuits it. Low priority — bounded and dwarfed by markdownlint-cli2, but genuinely unnecessary work when telemetry is off.

Detail

hook::emit_telemetry (plugins/markdown-formatter/hooks/hook-utils.sh) guards on the first line:

[[ -n "${HOOK_TELEMETRY_SINK:-}" ]] || return 0

That guard itself is free. But markdown-format.sh builds the telemetry payload before calling it, unconditionally:

  • the FILE_REL block — 2× cygpath calls on Windows;
  • data_json — 1× jq -n.

So ~3 telemetry-only subprocesses run per .md edit even when no sink is configured: ≈90ms on Windows (MSYS2 fork() ≈30ms each), ≈9ms on Linux. FILE_REL and data_json are used only for the envelope.

Suggested fix

Gate the FILE_REL + data_json construction behind a cheap sink-presence check (e.g. a hook::telemetry_enabled helper that just tests [[ -n "${HOOK_TELEMETRY_SINK:-}" ]]), so the unwired path does zero telemetry-only subprocesses. REPO_ROOT stays (it is also used for markdownlint config discovery).

Severity

Low — telemetry is opt-in; the cost is small and dominated by the lint itself. Capture, not block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions