Skip to content

Python-to-Go Migration #3

@mrjf

Description

@mrjf

schedule: every 6h

Python-to-Go Migration

Goal

Incrementally rewrite the APM CLI from Python to Go, one module at a time. This is an open-ended program: each iteration picks the next unmigrated module, writes durable benchmark scripts (if they don't already exist for that module), measures current Python performance, rewrites the module in Go, and measures again. The metric tracks what percentage of the original Python line count has been replaced by working Go code that passes all existing tests and benchmarks.

Each iteration must follow this loop:

  1. Select -- pick the next unmigrated Python module (start with leaf modules that have few internal dependencies: utils/, version.py, constants.py, config.py, then work inward).
  2. Benchmark (before) -- create or update a benchmark script in benchmarks/ that exercises the module's public API. Run it against the Python implementation and record the baseline.
  3. Rewrite -- implement the equivalent module in Go under cmd/apm/ (or internal/), preserving the exact CLI contract and public API surface.
  4. Benchmark (after) -- run the same benchmark script against the Go implementation and record the result.
  5. Validate -- run the full test suite (uv run --extra dev pytest tests/ -x -q) to confirm nothing is broken. The Go binary must be callable from the existing CLI entry point or replace it.
  6. Report -- update benchmarks/migration-status.json with the module name, before/after timings, and migration status.

The evaluation metric is the percentage of original Python source lines that have been replaced by tested Go code.

Target

Only modify these files:

  • cmd/ -- Go source tree (create as needed)
  • internal/ -- Go internal packages (create as needed)
  • go.mod -- Go module definition (create as needed)
  • go.sum -- Go dependency lock (create as needed)
  • Makefile -- build targets for Go binaries
  • benchmarks/ -- benchmark scripts and results (create as needed)
  • benchmarks/migration-status.json -- migration progress tracker
  • src/apm_cli/**/*.py -- Python source (to remove migrated modules and wire in Go replacements)
  • tests/**/*.py -- test updates to cover Go-backed modules

Do NOT modify:

  • .github/workflows/ -- CI workflows
  • .apm/ -- APM primitives
  • docs/ -- documentation (update separately)
  • pyproject.toml -- Python project config (until final cutover)

Evaluation

python3 -c "
import json, pathlib

status_file = pathlib.Path('benchmarks/migration-status.json')
if not status_file.exists():
    print(json.dumps({'python_lines_migrated_pct': 0.0}))
else:
    data = json.loads(status_file.read_text())
    total = data.get('original_python_lines', 71696)
    migrated = data.get('migrated_python_lines', 0)
    pct = round((migrated / total) * 100, 2) if total > 0 else 0.0
    print(json.dumps({'python_lines_migrated_pct': pct}))
"

The metric is python_lines_migrated_pct. Higher is better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions