Skip to content

⚡ Cache transform output to avoid redundant execution across formats#103

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/cache-transform-output
Draft

⚡ Cache transform output to avoid redundant execution across formats#103
Copilot wants to merge 2 commits intomainfrom
copilot/cache-transform-output

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

Transforms (emoji, variable substitution, syntax highlight) are pure functions of the input but were being executed once per output format — O(n_outputs) redundant work.

Changes

  • commands/build.rs: Move register_transforms + registry.apply_all before the output loop; clone the result into each pipeline invocation
  • Progress bar: Adjusted total from 2 × n_outputs1 + n_outputs to reflect the single shared transform pass
  • Error handling: Transform failure now immediately aborts the build (with context) rather than silently skipping per-format — correct behavior since transforms are format-independent
// Before
for output in outputs {
    let registry = register_transforms(&config.variables);
    let transformed = registry.apply_all(normalized_content.clone())?;
    pipeline.run_steps(transformed)?;
}

// After
let transformed = registry
    .apply_all(normalized_content)
    .with_context(|| "Transform pipeline failed; no output formats will be rendered")?;
for output in outputs {
    pipeline.run_steps(transformed.clone())?;
}

Tests Added

  • test_dry_run_multiple_outputs_succeeds — multi-format (html + pdf) dry-run succeeds without external tools
  • test_transforms_applied_once_content_consistent_across_formats — single vs. multi-output builds produce consistent results
Original prompt

This section details on the original issue you should resolve

<issue_title>⚡ Cache transform output to avoid redundant execution across formats</issue_title>
<issue_description>### Title: ⚡ Cache transform output to avoid redundant execution across formats


Description

Currently, the transform pipeline (emoji, variable substitution, syntax highlight) is executed once per output format.

For configurations with multiple outputs (HTML, PDF, DOCX), this results in:

O(n_outputs) repeated transform work

This is unnecessary because transforms are pure functions of the same input.


Goals

  • Execute transforms once per build
  • Reuse transformed content across all output formats
  • Improve performance with minimal changes

Requirements


1. Refactor Build Flow

In commands/build.rs:

Move transform execution outside the output loop:

Before:
for output in outputs:
    transformed = apply_transforms(input)
    render(transformed)

After:
transformed = apply_transforms(input)
for output in outputs:
    render(transformed)

2. Ensure Correctness

  • Ensure transforms are not output-format dependent
  • (future: allow format-specific transforms separately)

3. Logging

Log once:

Applying transforms (cached for all outputs)

4. Tests

  • verify transforms executed only once
  • verify output consistency across formats

Acceptance Criteria

  • Transforms run only once per build
  • Output remains correct
  • Performance improvement observable
  • Tests pass

Notes

This is a 5–10 minute change with immediate performance gain.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Refactor build flow to cache transform output ⚡ Cache transform output to avoid redundant execution across formats Mar 25, 2026
Copilot AI requested a review from szmyty March 25, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚡ Cache transform output to avoid redundant execution across formats

2 participants