I analyzed a simple call with fprof:

  fprof:trace(start),
  dnf_ty_variable:any(),
  fprof:trace(stop),
  fprof:profile(),
  fprof:analyse(),

This is the result. What are the bottlenecks?

%% Analysis results:
{  analysis_options,
 [{callers, true},
  {sort, acc},
  {totals, false},
  {details, true}]}.

%                                               CNT       ACC       OWN        
[{ totals,                                      311,   21.179,    7.253}].  %%%


%                                               CNT       ACC       OWN        
[{ "<0.405.0>",                                 311,undefined,    7.253}].   %%

{[{{debug_tests,slow_test,0},                     0,   21.118,    0.008},      
  {undefined,                                     0,    0.030,    0.021},      
  {{fprof,call,1},                                1,    0.013,    0.010}],     
 { {fprof,just_call,2},                           1,   21.161,    0.039},     %
 [{{error_handler,undefined_function,3},          1,   21.110,    0.015},      
  {{erlang,demonitor,1},                          1,    0.009,    0.009},      
  {{erlang,monitor,2},                            1,    0.003,    0.003},      
  {suspend,                                       1,    0.000,    0.000}]}.    

{[{undefined,                                     0,   21.149,    0.003}],     
 { {debug_tests,slow_test,0},                     0,   21.149,    0.003},     %
 [{{fprof,just_call,2},                           0,   21.118,    0.008},      
  {{fprof,trace,1},                               1,    0.028,    0.004}]}.    

{[{{fprof,just_call,2},                           1,   21.110,    0.015},      
  {{ty_tuples,any,0},                             1,    0.000,    0.012},      
  {{ty_rec,'-any/0-fun-0-',2},                    6,    0.000,    0.065},      
  {{ty_functions,any,0},                          1,    0.000,    0.011},      
  {{dnf_ty_variable,any,0},                       1,    0.000,    0.012},      
  {{dnf_ty_list,any,0},                           1,    0.000,    0.013}],     
 { {error_handler,undefined_function,3},         11,   21.110,    0.128},     %
 [{{error_handler,ensure_loaded,1},              11,   20.666,    0.086},      
  {{dnf_ty_variable,any,0},                       1,   18.435,    0.007},      
  {{ty_rec,any,0},                                1,   16.288,    0.004},      
  {{ty_tuples,any,0},                             1,    2.033,    0.006},      
  {{ty_functions,any,0},                          1,    1.991,    0.007},      
  {{dnf_ty_list,any,0},                           1,    1.517,    0.006},      
  {{erlang,function_exported,3},                 11,    0.032,    0.032},      
  {{dnf_ty_tuple,any,0},                          1,    0.008,    0.005},      
  {{dnf_ty_function,any,0},                       1,    0.008,    0.005},      
  {{ty_bool,any,0},                               1,    0.003,    0.003},      
  {{dnf_ty_predefined,any,0},                     1,    0.003,    0.003},      
  {{dnf_ty_interval,any,0},                       1,    0.003,    0.003},      
  {{dnf_ty_atom,any,0},                           1,    0.003,    0.003}]}.    

{[{{error_handler,undefined_function,3},         11,   20.666,    0.086}],     
 { {error_handler,ensure_loaded,1},              11,   20.666,    0.086},     %
 [{{code,ensure_loaded,1},                       11,   20.544,    0.197},      
  {{erlang,whereis,1},                           11,    0.036,    0.036}]}.    

{[{{error_handler,ensure_loaded,1},              11,   20.544,    0.197}],     
 { {code,ensure_loaded,1},                       11,   20.544,    0.197},     %
 [{{code,call,1},                                22,   14.595,    0.081},      
  {{code,ensure_prepare_loading,3},              11,    5.575,    0.043},      
  {{code,get_mode,0},                            11,    0.145,    0.044},      
  {{erlang,module_loaded,1},                     11,    0.032,    0.032}]}.    

{[{{error_handler,undefined_function,3},          1,   18.435,    0.007}],     
 { {dnf_ty_variable,any,0},                       1,   18.435,    0.007},     %
 [{{error_handler,undefined_function,3},          1,    0.000,    0.012}]}.    

{[{{error_handler,undefined_function,3},          1,   16.288,    0.004}],     
 { {ty_rec,any,0},                                1,   16.288,    0.004},     %
 [{{ty_rec,map,2},                                1,   16.284,    0.010}]}.    

{[{{ty_rec,any,0},                                1,   16.284,    0.010}],     
 { {ty_rec,map,2},                                1,   16.284,    0.010},     %
 [{{lists,foldl,3},                               1,   16.225,    0.008},      
  {{lists,zip,2},                                 1,    0.036,    0.004},      
  {{lists,seq,2},                                 1,    0.013,    0.003}]}.    

{[{{ty_rec,map,2},                                1,   16.225,    0.008}],     
 { {lists,foldl,3},                               1,   16.225,    0.008},     %
 [{{lists,foldl_1,3},                             1,   14.660,    0.008},      
  {{ty_rec,'-map/2-fun-0-',4},                    1,    1.557,    0.011}]}.    

{[{{lists,foldl_1,3},                             5,   14.619,    0.046},      
  {{lists,foldl,3},                               1,    1.557,    0.011}],     
 { {ty_rec,'-map/2-fun-0-',4},                    6,   16.176,    0.057},     %
 [{{ty_rec,'-any/0-fun-0-',2},                    6,   16.089,    0.031},      
  {{erlang,setelement,3},                         6,    0.030,    0.030}]}.    

{[{{ty_rec,'-map/2-fun-0-',4},                    6,   16.089,    0.031}],     
 { {ty_rec,'-any/0-fun-0-',2},                    6,   16.089,    0.031},     %
 [{{error_handler,undefined_function,3},          6,    0.000,    0.065}]}.    

{[{{lists,foldl,3},                               1,   14.660,    0.008},      
  {{lists,foldl_1,3},                             5,    0.000,    0.033}],     
 { {lists,foldl_1,3},                             6,   14.660,    0.041},     %
 [{{ty_rec,'-map/2-fun-0-',4},                    5,   14.619,    0.046},      
  {{lists,foldl_1,3},                             5,    0.000,    0.033}]}.    

{[{{code,ensure_loaded,1},                       22,   14.595,    0.081}],     
 { {code,call,1},                                22,   14.595,    0.081},     %
 [{{code_server,call,1},                         22,   14.514,    0.397}]}.    

{[{{code,call,1},                                22,   14.514,    0.397}],     
 { {code_server,call,1},                         22,   14.514,    0.397},     %
 [{suspend,                                      22,   13.926,    0.000},      
  {{erlang,monitor,2},                           22,    0.096,    0.096},      
  {{erlang,demonitor,2},                         22,    0.095,    0.095}]}.    

{[{{code_server,call,1},                         22,   13.926,    0.000},      
  {{fprof,just_call,2},                           1,    0.000,    0.000}],     
 { suspend,                                      23,   13.926,    0.000},     %
 [ ]}.

{[{{code,ensure_loaded,1},                       11,    5.575,    0.043}],     
 { {code,ensure_prepare_loading,3},              11,    5.575,    0.043},     %
 [{{erlang,prepare_loading,2},                   11,    5.532,    0.048}]}.    

{[{{code,ensure_prepare_loading,3},              11,    5.532,    0.048}],     
 { {erlang,prepare_loading,2},                   11,    5.532,    0.048},     %
 [{{erlang,prepare_loading_1,2},                 11,    5.484,    0.091}]}.    

{[{{erlang,prepare_loading,2},                   11,    5.484,    0.091}],     
 { {erlang,prepare_loading_1,2},                 11,    5.484,    0.091},     %
 [{{erts_internal,prepare_loading,2},            11,    5.393,    5.393}]}.    

{[{{erlang,prepare_loading_1,2},                 11,    5.393,    5.393}],     
 { {erts_internal,prepare_loading,2},            11,    5.393,    5.393},     %
 [ ]}.

{[{{error_handler,undefined_function,3},          1,    2.033,    0.006}],     
 { {ty_tuples,any,0},                             1,    2.033,    0.006},     %
 [{{error_handler,undefined_function,3},          1,    0.000,    0.012}]}.    

{[{{error_handler,undefined_function,3},          1,    1.991,    0.007}],     
 { {ty_functions,any,0},                          1,    1.991,    0.007},     %
 [{{error_handler,undefined_function,3},          1,    0.000,    0.011}]}.    

{[{{error_handler,undefined_function,3},          1,    1.517,    0.006}],     
 { {dnf_ty_list,any,0},                           1,    1.517,    0.006},     %
 [{{error_handler,undefined_function,3},          1,    0.000,    0.013}]}.    

{[{{code,ensure_loaded,1},                       11,    0.145,    0.044}],     
 { {code,get_mode,0},                            11,    0.145,    0.044},     %
 [{{code_server,get_mode,0},                     11,    0.101,    0.065}]}.    

{[{{code,get_mode,0},                            11,    0.101,    0.065}],     
 { {code_server,get_mode,0},                     11,    0.101,    0.065},     %
 [{{persistent_term,get,1},                      11,    0.036,    0.036}]}.    

{[{{code_server,call,1},                         22,    0.096,    0.096},      
  {{fprof,just_call,2},                           1,    0.003,    0.003}],     
 { {erlang,monitor,2},                           23,    0.099,    0.099},     %
 [ ]}.

{[{{code_server,call,1},                         22,    0.095,    0.095}],     
 { {erlang,demonitor,2},                         22,    0.095,    0.095},     %
 [ ]}.

{[{{error_handler,ensure_loaded,1},              11,    0.036,    0.036},      
  {{fprof,call,1},                                1,    0.004,    0.004}],     
 { {erlang,whereis,1},                           12,    0.040,    0.040},     %
 [ ]}.

{[{{code_server,get_mode,0},                     11,    0.036,    0.036}],     
 { {persistent_term,get,1},                      11,    0.036,    0.036},     %
 [ ]}.

{[{{ty_rec,map,2},                                1,    0.036,    0.004}],     
 { {lists,zip,2},                                 1,    0.036,    0.004},     %
 [{{lists,zip,3},                                 1,    0.032,    0.009}]}.    

{[{{lists,zip,2},                                 1,    0.032,    0.009},      
  {{lists,zip,3},                                 6,    0.000,    0.023}],     
 { {lists,zip,3},                                 7,    0.032,    0.032},     %
 [{{lists,zip,3},                                 6,    0.000,    0.023}]}.    

{[{{code,ensure_loaded,1},                       11,    0.032,    0.032}],     
 { {erlang,module_loaded,1},                     11,    0.032,    0.032},     %
 [ ]}.

{[{{error_handler,undefined_function,3},         11,    0.032,    0.032}],     
 { {erlang,function_exported,3},                 11,    0.032,    0.032},     %
 [ ]}.

{[{{ty_rec,'-map/2-fun-0-',4},                    6,    0.030,    0.030}],     
 { {erlang,setelement,3},                         6,    0.030,    0.030},     %
 [ ]}.

{[{{debug_tests,slow_test,0},                     1,    0.028,    0.004}],     
 { {fprof,trace,1},                               1,    0.028,    0.004},     %
 [{{fprof,call,1},                                1,    0.024,    0.007}]}.    

{[{{fprof,trace,1},                               1,    0.024,    0.007}],     
 { {fprof,call,1},                                1,    0.024,    0.007},     %
 [{{fprof,just_call,2},                           1,    0.013,    0.010},      
  {{erlang,whereis,1},                            1,    0.004,    0.004}]}.    

{[{{ty_rec,map,2},                                1,    0.013,    0.003}],     
 { {lists,seq,2},                                 1,    0.013,    0.003},     %
 [{{lists,seq_loop,3},                            1,    0.010,    0.004}]}.    

{[{{lists,seq,2},                                 1,    0.010,    0.004},      
  {{lists,seq_loop,3},                            2,    0.000,    0.006}],     
 { {lists,seq_loop,3},                            3,    0.010,    0.010},     %
 [{{lists,seq_loop,3},                            2,    0.000,    0.006}]}.    

{[{{error_handler,undefined_function,3},          1,    0.003,    0.003},      
  {{dnf_ty_tuple,any,0},                          1,    0.003,    0.003},      
  {{dnf_ty_function,any,0},                       1,    0.003,    0.003}],     
 { {ty_bool,any,0},                               3,    0.009,    0.009},     %
 [ ]}.

{[{{fprof,just_call,2},                           1,    0.009,    0.009}],     
 { {erlang,demonitor,1},                          1,    0.009,    0.009},     %
 [ ]}.

{[{{error_handler,undefined_function,3},          1,    0.008,    0.005}],     
 { {dnf_ty_tuple,any,0},                          1,    0.008,    0.005},     %
 [{{ty_bool,any,0},                               1,    0.003,    0.003}]}.    

{[{{error_handler,undefined_function,3},          1,    0.008,    0.005}],     
 { {dnf_ty_function,any,0},                       1,    0.008,    0.005},     %
 [{{ty_bool,any,0},                               1,    0.003,    0.003}]}.    

{[{{error_handler,undefined_function,3},          1,    0.003,    0.003}],     
 { {dnf_ty_predefined,any,0},                     1,    0.003,    0.003},     %
 [ ]}.

{[{{error_handler,undefined_function,3},          1,    0.003,    0.003}],     
 { {dnf_ty_interval,any,0},                       1,    0.003,    0.003},     %
 [ ]}.

{[{{error_handler,undefined_function,3},          1,    0.003,    0.003}],     
 { {dnf_ty_atom,any,0},                           1,    0.003,    0.003},     %
 [ ]}.

{[ ],
 { undefined,                                     0,    0.000,    0.000},     %
 [{{debug_tests,slow_test,0},                     0,   21.149,    0.003},      
  {{fprof,just_call,2},                           0,    0.030,    0.021}]}.