trailblazer-activity icon indicating copy to clipboard operation
trailblazer-activity copied to clipboard

Idea: Performance better with while loop

Open apotonick opened this issue 2 years ago • 6 comments

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

apotonick avatar Nov 24 '22 09:11 apotonick

In DSL, we could use the Start event for modelling, only, and skip it when compiling the activity.

apotonick avatar Nov 24 '22 09:11 apotonick

In Circuit#call, it should be return [task, args]

apotonick avatar Nov 24 '22 09:11 apotonick

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
          )

apotonick avatar Nov 24 '22 09:11 apotonick

It seems that

return [last_signal, args]

is faster than

return last_signal, args

apotonick avatar Nov 24 '22 09:11 apotonick

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?

apotonick avatar Nov 24 '22 14:11 apotonick

TODO: check if caller_locations in DSL.apply_step_on_sequence_builder makes it slower. We need it for deprecation warnings.

apotonick avatar Nov 29 '22 13:11 apotonick