trailblazer-activity
trailblazer-activity copied to clipboard
Idea: Performance better with while loop
In Circuit#call
, a while loop that also doesn't call
termini anymore improves from 1.23 to 1.55.
def call(args, start_task: @start_task, runner: Runner, **circuit_options)
circuit_options = circuit_options.merge(runner: runner) # TODO: set the :runner option via arguments_for_call to save the merge?
task = start_task
last_signal = nil
while ! @stop_events.include?(task) do
last_signal, args, _discarded_circuit_options = runner.(
task,
args,
**circuit_options
)
# Stop execution of the circuit when we hit a stop event (< End). This could be an task's End or Suspend.
# if @stop_events.include?(task)
if (next_task = next_for(task, last_signal))
task = next_task
else
raise IllegalSignalError.new(
task,
signal: last_signal,
outputs: @map[task],
exec_context: circuit_options[:exec_context], # passed at run-time from DSL
)
end
end
return [ last_signal, args ]
end
In DSL, we could use the Start
event for modelling, only, and skip it when compiling the activity.
In Circuit#call
, it should be return [task, args]
It is slower to call the Runner
with **circuit_options
. The Runner could internally do that when calling the task.
runner.(
task,
args,
circuit_options
)
It seems that
return [last_signal, args]
is faster than
return last_signal, args
The entire idea of the circuit interface with a nested (ctx, flow_options)
and a kw **circuit_options
is probably not so clever anymore, we could simply pass all three as positionals, maybe that's a ton faster?
TODO: check if caller_locations in DSL.apply_step_on_sequence_builder makes it slower. We need it for deprecation warnings.