Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache symbol completion result #1021

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented Oct 17, 2024

Make symbol completion faster

  • Cache Symbol.all_symbols.sort and reuse it.
  • Restrict the number of symbol candidates to reduce completion/rendering cost in Reline.
  • Use bsearch to perform O(logN) search from cached sorted symbol list.
irb -f
irb(main):001> s='a';symbols = 100000.times.map{s=s.succ; [s.to_sym, ('a'+s).to_sym]};
irb(main):002> :aaabq
               :aaabk 
               :aaabl 
               :aaabm 
               :aaabn 
               :aaabo 
               :aaabp 
               :aaabq▄
               :azyd █
               :azye ▀
               :azyf  
               :azyg  
               :azyh  
               :azyi  
               :azyj  
               :azyk  

Completion candidates of symbol contains first 50 + last 50 symbols matched to the completion target.

@tompng tompng force-pushed the faster_symbol_completion_with_cache branch from f012adc to b11e2dd Compare October 19, 2024 20:19
@tompng tompng force-pushed the faster_symbol_completion_with_cache branch from b11e2dd to 326a56a Compare October 20, 2024 05:48

commands | result.completion_candidates.map { target + _1 }
analyze_result = result.instance_variable_get(:@analyze_result)
if analyze_result.is_a?(Array) && analyze_result[0] == :symbol && analyze_result[1].is_a?(String)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is relatively safe because it checks the value strictly, but it's a bit hacky...

@tompng tompng marked this pull request as ready for review October 20, 2024 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant