Skip to content

perf: cache token encoder with sync.Once#34

Merged
dacharyc merged 1 commit intoagent-ecosystem:mainfrom
x3c3:perf/cache-token-encoder
Mar 20, 2026
Merged

perf: cache token encoder with sync.Once#34
dacharyc merged 1 commit intoagent-ecosystem:mainfrom
x3c3:perf/cache-token-encoder

Conversation

@philoserf
Copy link
Contributor

Summary

  • Initialize the tokenizer once via sync.Once instead of on every CheckTokens call

Test plan

  • Existing token tests pass
  • Race detector clean

🤖 Generated with Claude Code

CheckTokens previously created a new tokenizer.Get(O200kBase) on every
call. The encoder is now initialized once at package level via sync.Once
and reused across invocations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Member

@dacharyc dacharyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dacharyc dacharyc merged commit e865b72 into agent-ecosystem:main Mar 20, 2026
2 checks passed
@philoserf philoserf deleted the perf/cache-token-encoder branch March 20, 2026 04:15
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.

2 participants