From ff3903fe9346199e39538a39ea4e5a5694e31541 Mon Sep 17 00:00:00 2001 From: Phil Murray Date: Mon, 20 Feb 2023 15:24:43 +1300 Subject: [PATCH] Speed up nested #simple_fields_for usage by a considerable amount Exceptions are slow due to generating backtraces - and then when other debugging gems (such as did_you mean, which are included with Ruby and Rails these days) get involved it resulted in excessive Object allocation. --- lib/simple_form/form_builder.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index da723cb7..32acf5d5 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -672,12 +672,7 @@ def mapping_override(klass) 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 + return at.const_get(mapping) if at.const_defined?(mapping) end def attempt_mapping_with_custom_namespace(input_name)