php - Symfony\Component\Form\Form::handleRequest performance raises eyebrows -
my question is, why handlerequest method inordinately slow in relation other operations in request? handlerequest takes long rendering template. there no database or doctrine orm involved in entity, plain php class being used bind user data form. have put reasonable validation on entity, removing validation annotation virtually nothing improve performance of method.
i'm using symfony 3.0.6 , php 7.0.7
controller
public function postsearchaction(request $request, $page = null) { $this->setrequestpage($request, $page); $formdata = new searchrequest(); $this->starttimeline("building form"); $searchrequestform = $this->createform(searchtype::class, $formdata, array( 'action' => $this->generateurl('api_search_post'), 'method' => 'post', )); $this->stoptimeline("building form"); $this->starttimeline("handle request"); $searchrequestform->handlerequest($request); $this->stoptimeline("handle request"); if ($searchrequestform->isvalid()) { $formdata = $searchrequestform->getdata(); $this->starttimeline("build service request"); $searchrequest = $this->get('search')->buildrequest($formdata); $this->stoptimeline("build service request"); if ($formdata->getsearchtype() === searchrequest::type_vehicle) { $search = $this->get('search')->getvehicle($searchrequest, $this->getstopwatch()); } else { $search = $this->get('search')->getstorage($searchrequest, $this->getstopwatch()); } } else { $search = $searchrequestform; } $view = $this->view($search, 200) ->setserializationcontext($this->getserializationcontext()) ->settemplate("restapibundle:search:postsearch.html.twig") ->settemplatevar('search') ->settemplatedata(array( 'form' => $searchrequestform->createview() )); return $this->handleview($view); }
form
public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('location', texttype::class) ->add('page', hiddentype::class, ['required' => false]) ->add('searchtype', choicetype::class, [ 'required' => true, 'label' => 'search type', 'choices' =>[ 'storage' => searchrequest::type_storage, 'vehicle' => searchrequest::type_vehicle ]]) ->add('squarefoot', choicetype::class, [ 'required' => false, 'label' => 'unit size', 'placeholder' => 'unit size', 'choices' => [ '5\' x 5\'' => 25, '5\' x 10\'' => 50, '5\' x 15\'' => 75, '10\' x 10\'' => 100, '10\' x 15\'' => 150, '10\' x 20\'' => 200, '10\' x 25\'' => 250, '10\' x 30\'' => 300, 'default' => 0 ]]) ->add('sort', choicetype::class, [ 'required' => false, 'label' => 'sort by', 'placeholder' => 'sort by', 'choices' => [ 'distance' => searchrequest::sort_distance, 'price' => searchrequest::sort_price, 'rating' => searchrequest::sort_ratings, 'default' => searchrequest::sort_default ]]) ->add('moveindate', datetype::class, [ 'widget' => 'single_text', 'required' => false ]) ->add('filterclimatecontrolled', checkboxtype::class, [ 'value' => 'true', 'required' => false, 'label' => 'climate controlled' ]) ->add('filter24houraccess', checkboxtype::class, [ 'value' => 'true', 'required' => false, 'label' => '24 hour access' ]) ->add('filterdriveupaccess', checkboxtype::class, [ 'value' => 'true', 'required' => false, 'label' => 'drive access' ]) ->add('search', submittype::class); }
entity
class searchrequest { const sort_distance = 'distance'; const sort_price = 'price'; const sort_ratings = 'ratings'; const sort_default = 'default'; const type_vehicle = 'vehicle'; const type_storage = 'storage'; /** * @var string * @assert\notblank() */ protected $location; /** * @var int * @assert\type( * type="numeric" * ) */ protected $page = 1; /** * @var double * @assert\type( * type="numeric" * ) */ protected $squarefoot; /** * @var string * @assert\expression( * "this.getsort() in this.getsortlist()", * message="invalid sort type." * ) */ protected $sort; /** * @var string * @assert\expression( * "this.getsearchtype() in this.getsearchtypelist()", * message="invalid search type." * ) */ protected $searchtype; /** * @var string * @assert\date() * @serializer\type("datetime") */ protected $moveindate; /** * @var boolean * @assert\type( * type="bool" * ) */ protected $filterclimatecontrolled; /** * @var boolean * @assert\type( * type="bool" * ) */ protected $filter24houraccess; /** * @var boolean * @assert\type( * type="bool" * ) */ protected $filterdriveupaccess; public function getsortlist() { return [ null, self::sort_distance, self::sort_price, self::sort_ratings, self::sort_default ]; } public function getsearchtypelist() { return [ self::type_vehicle, self::type_storage ]; }