Skip to content

Commit

Permalink
Optimize startup: Defer initializing default matcher
Browse files Browse the repository at this point in the history
This turns `@time using InteractiveCodeSearch` from ~0.8 seconds to ~0.06
seconds.
  • Loading branch information
tkf committed Oct 30, 2020
1 parent 5949911 commit 15eee09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/InteractiveCodeSearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct Recursive <: SearchPolicy end

mutable struct SearchConfig # CONFIG
open
interactive_matcher::Cmd
interactive_matcher::Union{Nothing,Cmd}
auto_open::Bool
trigger_key::Union{Nothing,Char}
end
Expand Down Expand Up @@ -188,8 +188,7 @@ function parse_loc(line)
end

function run_matcher(input)
maybe_warn_matcher()
return String(read_stdout(input, CONFIG.interactive_matcher))
return String(read_stdout(input, get_interactive_matcher()))
end

choose_method(methods::T) where T =
Expand Down Expand Up @@ -284,7 +283,7 @@ using InteractiveCodeSearch
"""
const CONFIG = SearchConfig(
edit, # open
`peco`, # interactive_matcher
nothing, # interactive_matcher
true, # auto_open
')', # trigger_key
)
Expand Down Expand Up @@ -553,14 +552,24 @@ function maybe_warn_matcher(cmd = CONFIG.interactive_matcher)
end
end

function get_interactive_matcher()
cmd = CONFIG.interactive_matcher
if cmd === nothing
CONFIG.interactive_matcher = cmd = choose_interactive_matcher()
end
cmd::Cmd
maybe_warn_matcher(cmd)
return cmd
end

function __init__()
CONFIG.interactive_matcher = choose_interactive_matcher()
setup_keybinds()
end

include("taskmanager.jl")
include("history.jl")
include("return.jl")
include("keybinds.jl")
if VERSION < v"1.2"
include("return.jl")
end

end # module
2 changes: 2 additions & 0 deletions src/return.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export @searchreturn

using Base: unwrap_unionall

include("taskmanager.jl")

struct CallableFinder{P <: SearchPolicy}
modules::AbstractVector{Module}
sp::P
Expand Down

0 comments on commit 15eee09

Please sign in to comment.