ruby / irb

interactive Ruby
BSD 2-Clause "Simplified" License
392 stars 119 forks source link

Cache symbol completion result #1021

Closed tompng closed 3 weeks ago

tompng commented 1 month ago

Make symbol completion faster

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 commented 1 month ago

I think there is room for discussion whether to keep symbol completion or to drop it.

If we're going to keep it, we need to do this bsearch because symbol filtering (main bottleneck in IRB side) is few times slower than Symbol.all_symbols.

tompng commented 3 weeks ago

In the following situation, Symbol.all_symbol.sort takes about a second. I think it is not acceptable.

Symbol.all_symbols.size is 100000 with average symbol length=15 (About the number in Rails app) Running in docker (host and image platform mismatch)