Skip to content

Commit 2e9d3df

Browse files
committed
one more optimization attempt
1 parent 195a9c7 commit 2e9d3df

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/interface/interface.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ The state is modified in-place.
4343
All keyword arguments are passed to the [`initialize_state!`](@ref)`(problem, algorithm, state)` function.
4444
"""
4545
function solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
46-
logger = ALGORITHM_LOGGER[]
46+
logger = algorithm_logger()
4747
initialize_state!(problem, algorithm, state; kwargs...)
48-
LOGGING_ENABLED[] && handle_message(logger, problem, algorithm, state, :Start)
48+
isnothing(logger) || handle_message(logger, problem, algorithm, state, :Start)
4949
while !is_finished!(problem, algorithm, state)
50-
LOGGING_ENABLED[] && handle_message(logger, problem, algorithm, state, :PreStep)
50+
isnothing(logger) || handle_message(logger, problem, algorithm, state, :PreStep)
5151
increment!(state)
5252
step!(problem, algorithm, state)
53-
LOGGING_ENABLED[] && handle_message(logger, problem, algorithm, state, :PostStep)
53+
isnothing(logger) || handle_message(logger, problem, algorithm, state, :PostStep)
5454
end
55-
LOGGING_ENABLED[] && handle_message(logger, problem, algorithm, state, :Stop)
55+
isnothing(logger) || handle_message(logger, problem, algorithm, state, :Stop)
5656
return state
5757
end
5858

src/logging.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ Scoped value for handling the logging events of arbitrary algorithms.
111111
"""
112112
const ALGORITHM_LOGGER = ScopedValue(AlgorithmLogger())
113113

114+
function algorithm_logger()
115+
LOGGING_ENABLED[] || return nothing
116+
logger = ALGORITHM_LOGGER[]
117+
isempty(logger.actions) && return nothing
118+
return logger
119+
end
120+
114121
# @inline here to enable the cheap global check
115122
@inline function log!(problem::Problem, algorithm::Algorithm, state::State, context::Symbol; kwargs...)
116123
if LOGGING_ENABLED[]

0 commit comments

Comments
 (0)