Speed initialization of dynamic fields of dialog


#1

hi, miq developers
I am using darga branch of miq, I find the initialization of dynamic fields of dialog is very slow. I read the code and find this:

  def init_fields_with_values(values)
    dialog_field_hash.each do |key, field|
      values[key] = field.value
      field.dialog   = self
    end
    dialog_field_hash.each { |key, field| values[key] = field.initialize_with_values(values) }
    dialog_field_hash.each { |_key, field| field.update_values(values) }
  end

So field.initialize_with_values is called in serial. Is it passible to run this in parallel. If this, I think it will speed a lot.

I try to speed this by multi-thread, but it doesn’t work

  def init_fields_with_values(values)
    dialog_field_hash.each do |key, field|
      values[key] = field.value
      field.dialog   = self
    end
    dialog_initialize_threads = []
    dialog_field_hash.each do |key, field|
      t = Thread.new do
        values[key] = field.initialize_with_values(values)
      end
      dialog_initialize_threads << t
    end
    dialog_initialize_threads.each do |t|
      t.join
    end
    dialog_field_hash.each { |_key, field| field.update_values(values) }
  end

The process will just hang.


#2

@dmetzger can you review this question from @wangxiangyu and forward to a SME if necessary.


#3

@kbrock would you please review and comment on the proposed performance enhancement to dynamic field dialogs.


#4

Thank you @wangxiangyu

It would be nice if we could fix this issue without using threads.
But highlighting a block of code that is troublesome is very helpful.

@gmccullough Have you found init_fields_with_values to be a bottleneck. Is the issue in get_default_value?


#5

Using dynamic fields means their settings and values come from automate. There is an inherent overhead to running automate methods to populate these properties.

As far as running in parallel, we would first need to define dependencies between fields before we could introduce this. Fields can rely on the value of other fields and doing all this work in parallel would lead to issues with the current configuration.