From 15eee0958fc8bb6caf82dbfbd3e5a86b1b033ca7 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 30 Oct 2020 00:27:40 -0400 Subject: [PATCH] Optimize startup: Defer initializing default matcher This turns `@time using InteractiveCodeSearch` from ~0.8 seconds to ~0.06 seconds. --- src/InteractiveCodeSearch.jl | 23 ++++++++++++++++------- src/return.jl | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/InteractiveCodeSearch.jl b/src/InteractiveCodeSearch.jl index 66d3c3b..8c7839d 100644 --- a/src/InteractiveCodeSearch.jl +++ b/src/InteractiveCodeSearch.jl @@ -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 @@ -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 = @@ -284,7 +283,7 @@ using InteractiveCodeSearch """ const CONFIG = SearchConfig( edit, # open - `peco`, # interactive_matcher + nothing, # interactive_matcher true, # auto_open ')', # trigger_key ) @@ -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 diff --git a/src/return.jl b/src/return.jl index 6c10616..9bda056 100644 --- a/src/return.jl +++ b/src/return.jl @@ -2,6 +2,8 @@ export @searchreturn using Base: unwrap_unionall +include("taskmanager.jl") + struct CallableFinder{P <: SearchPolicy} modules::AbstractVector{Module} sp::P