perf: optimize string concatenation and namespace caching#230
Merged
sudo-tee merged 1 commit intosudo-tee:mainfrom Feb 3, 2026
Merged
perf: optimize string concatenation and namespace caching#230sudo-tee merged 1 commit intosudo-tee:mainfrom
sudo-tee merged 1 commit intosudo-tee:mainfrom
Conversation
Replace inefficient string concatenation loops with table.concat to improve performance when building base62 IDs and timestamp hex strings. Cache namespace ID creation in input_window to avoid repeated API calls.
Contributor
Author
|
This is a little optimize, it will increase our performance a bit |
Owner
|
The id calss is rarely used. I think it's only used for the init command. But I am ok with it being more optimized. It was a loose port from the opencode implementation in typescript Thanks for the PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
table.concatin ID generationChanges
lua/opencode/id.luarandom_base62(): Use table +table.concatinstead ofresult = result .. char(O(n) vs O(n²))generate_new_id(): Same optimization for timestamp byte extractionlua/opencode/ui/input_window.luaplaceholder_nsat module levelnvim_create_namespace('input_placeholder')callsWhy
String concatenation in Lua creates new string objects each iteration, causing O(n²) complexity. While the impact is minimal for short strings (26 chars), this follows better Lua practices.
Namespace IDs are stable for the same name, but caching avoids unnecessary function calls on every placeholder refresh.