This may be related to our Gemfile, and some additional gems that are extending the exception message processing, however what we are seeing is that in FormBuilder
def attempt_mapping(mapping, at)
return if SimpleForm.inputs_discovery == false && at == Object
begin
at.const_get(mapping)
rescue NameError => e
raise if e.message !~ /#{mapping}$/
end
end
the raise if e.message !~ /#{mapping}$/ is taking over 1000ms for the first lookup of that type of field (e.g. NumericInput) on a form. I believe that it's attempting to check if the exception message contains the name of the class that was searched for, e.g. (from my hacking about earlier to see what the issue was)
If I change the above line of code to raise unless e.is_a? NameError then the execution time drops to < 1 ms, e.g.
15:42:17 web.1 | SJH attempt_mapping RAISE TIME = 0.008567
I believe that this keeps the same behaviour, as it will raise the exception if there's anything other than the NameError that was being checked for.
I don't believe the slow down is due to simple_form, the line of code in question hasn't changed in 10 years, and we can see the same slow down if we just log out the exception message in the function, e.g.
puts "SJH attempt_mapping #{e.inspect}"
also takes 1000 ms. But I believe the change from raise if e.message !~ /#{mapping}$/ to raise unless e.is_a? NameError should be relatively low risk to implement in simple_form and would prevent others from tripping over this. We aren't experiencing this behaviour elsewhere in our application as we handling exceptions based on their type rather than their contents.
Environment
Current behavior
This may be related to our Gemfile, and some additional gems that are extending the exception message processing, however what we are seeing is that in
FormBuilder
the
raise if e.message !~ /#{mapping}$/
is taking over 1000ms for the first lookup of that type of field (e.g.NumericInput
) on a form. I believe that it's attempting to check if the exception message contains the name of the class that was searched for, e.g. (from my hacking about earlier to see what the issue was)If I change the above line of code to
raise unless e.is_a? NameError
then the execution time drops to < 1 ms, e.g.I believe that this keeps the same behaviour, as it will raise the exception if there's anything other than the NameError that was being checked for.
I don't believe the slow down is due to simple_form, the line of code in question hasn't changed in 10 years, and we can see the same slow down if we just log out the exception message in the function, e.g.
also takes 1000 ms. But I believe the change from
raise if e.message !~ /#{mapping}$/
toraise unless e.is_a? NameError
should be relatively low risk to implement in simple_form and would prevent others from tripping over this. We aren't experiencing this behaviour elsewhere in our application as we handling exceptions based on their type rather than their contents.