Skip to content

Native version #337

Backlog
Backlog

Description

@bric3

Hi there, given the number of sessions that may be opened and with sub-agents, python is eating sufficiently memory and CPU to be noticeable.

I ended up vibecoding a port in Rust, which have better numbers. And I suppose this ought to be considered on this project.

On an Apple M4 Max, the native release hook ran 1.9x to 4.8x faster than the
pinned Python hook across four offline Claude Code workloads. The controlled
rerun on 20 November 2026 recorded these medians:

Workload Python wall time, ms Rust wall time, ms Python CPU, ms Rust CPU, ms Python peak RSS, bytes Rust peak RSS, bytes
Start a session 74.25 15.45 60 0 27,131,904 9,830,400
Record one result 70.59 15.38 50 0 27,148,288 10,715,136
Fold 96 calls 84.27 23.21 50 0 27,590,656 15,663,104
Fold 3,072 calls 166.68 89.47 140 60 42,827,776 30,654,464

Personally, I don't plan to maintain the port regularly. But the proof of concept works.

Activity

  1. github-actions commented on Nov 26, 2026

    @github-actions

    Scout plan

    Issue: #337 — Native version

    Understanding

    The issue proposes considering a native (Rust) hook implementation. The reporter measured the Python hook at 70–167 ms wall time and about 27–43 MB peak RSS, against 15–89 ms and 10–31 MB for their port at https://github.com/bric3/TokenEconomizer-native. They don't plan to maintain it. No specific change to this repository is requested. It is a design proposal that needs a maintainer decision, and the numbers are the reporter's own and not reproduced here.

    Approach

    No change proposed.

    Context for the maintainers: CLAUDE.md makes the package standard-library-only Python (>= 3.10), and hooks must start fast and fail open. A second implementation would have to match tokeneconomizer/plugin/ hook dispatch and the on-disk state (injection.json, untool.json, envelope.json, event kinds), and the offline tests in tests/ and experiments/tests/ pin the Python behavior. If a maintainer wants to pursue this, a cheaper first step could be profiling Python hook startup (imports in tokeneconomizer/plugin/) before any rewrite.

    Verification

    Not applicable.

    Open questions

    None.

    Generated by Scout for #337 · claude · sonnet55 · ~10 AIC · ⌖ ~16 AIC · ⊞ 2.6K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions