Improve extremely slow 'drupal_process_form' I am having problem investigating why our profile edit page is damn slow.

Call Stack
#   Time    Memory  Function    Location
1   0.0003  276344  {main}( )   ...\index.php:0
2   1.6889  39666816    menu_execute_active_handler( )  ...\index.php:21
3   1.6899  39668968    call_user_func_array:{C:\wamp\www\hyperDrupal\includes\menu.inc:527} ( )    ...\menu.inc:527
4   1.6899  39669448    entity_ui_get_form( )   ...\menu.inc:527
5   1.6901  39696720    drupal_build_form( )    ...\entity.module:1282
6   1.7842  40984120    drupal_process_form( )  ...\form.inc:385
(7) 17.3247 58502824    form_execute_handlers( )    ...\form.inc:903
8   17.3247 58503344    profile2_form_submit_handler( ) ...\form.inc:1519
9   17.3265 58492400    profile2_save( )    ...\profile2.module:621
10  17.3265 58492528    Profile-&gt;save( )    ...\profile2.module:311
11  17.3265 58491736    Entity-&gt;save( ) ...\profile2.module:918
12  17.3265 58492096    EntityAPIController-&gt;save( )    ...\entity.inc:333
13  17.3737 58517352    EntityAPIController-&gt;invoke( )  ...\entity.controller.inc:462
(14)    23.5502 90243232    module_invoke_all( )    ...\entity.controller.inc:355
15  23.5511 90247648    call_user_func_array:{C:\wamp\www\hyperDrupal\includes\module.inc:951} ( )  ...\module.inc:951
16  23.5511 90248096    bdEvent_entity_update( )    ...\module.inc:951
17  23.5511 90248832    bdE\bdEvent-&gt;dispatch( )    ...\bdEvent.module:44
18  23.5567 90332840    bdE\Services\profileService-&gt;run( ) ...\bdEvent.php:38
19  23.5568 90333120    bdE\Services\profileService-&gt;entity_get_values( )   ...\profileService.php:24


I created a stack trace in a new module and times are huge. Check step 7 and 14 both are after long operations. 

What could be taking so much between 

6   1.7842  40984120    drupal_process_form( )  ...\form.inc:385
7   17.3247 58502824    form_execute_handlers( )    ...\form.inc:903


and between

13  17.3737 58517352    EntityAPIController-&gt;invoke( )  ...\entity.controller.inc:462
14  23.5502 90243232    module_invoke_all( )    ...\entity.controller.inc:355
Based on the backtrace, you won't know why your site is slow.

You should run a proper PHP profiler and analyse the results which can identify the slowest components.

It doesn't have to be Drupal it-self, but could be lack of caching or misconfiguration.

Some suggestions:


disable modules which you don't need (e.g. Devel, core Database Logging module, etc.),
upgrade your PHP to the latest or higher branch,
recompile your PHP for 64-bit or higher architecture depending on your CPU,
use the faster storage device for your db files or whole LAMP environment (e.g. SSD or memory-based filesystem),
use PHP debugger or profiler to find out any performance bottleneck (e.g. XDebug Profiler, DTrace or NuSphere PhpED PHP Profiler),
run some time-consuming drush command under gprof profiling tool, so you can find some performance bottleneck as well.


If disabling slow modules or profiling won't help, see: How do you improve Drupal performance?