Skip to content

πŸ€– perf: token stats for 1M-row chats take ~55 s and hit the renderer's 60 s timeoutΒ #4653

Description

@ThomasK33

Found while fixing #4643 (PR #4647). The fix only stops the server stall; the calculation itself is still slow.

Problem

tokenizer.calculateStats on a 1.24M-row active epoch takes ~45–57 s: one worker.postMessage and one promise per message, a single tokenizer worker. The renderer's CALCULATION_TIMEOUT_MS (60 s, WorkspaceConsumerManager.ts) fired in local browser runs under load on both base and fix (Calculation failed … Calculation timeout), leaving the Stats/Cost tab empty even though the backend finishes and persists session-usage.json shortly after. Peak live heap during the calculation is ~1.9 GB (message array + 1.24M pending requests).

Options

  • Batch worker requests (one message per N texts) to cut clone/promise overhead.
  • Approximate counts for epochs far beyond any model's context window.
  • Let the renderer pick up the persisted cache when its request times out.

Repro recipe and probe: see the root-cause comment on #4643.


Generated with xum β€’ Model: anthropic:claude-opus-5-5 β€’ Thinking: high β€’ Cost: $9.90

Activity

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