When profiling a Symfony2 application displaying a CMS generated page of 
medium complexity (leading to about 800 controller requests) we saw quite a 
negative performance impact coming from 
Symfony\Component\HttpFoundation\Request::initialize(), especially since 
$this->server->getHeaders() is called every time.

I made the following modification to the duplicate() method, for me 
everything seems fine (and faster), but I don't know if there are any side 
effects which I might have missed:

     public function duplicate(array $query = null, array $request = null, 
array $attributes = null, array $cookies = null, array $files = null, array 
$server = null)
     {
         $dup = clone $this;
-        $dup->initialize(
-            null !== $query ? $query : $this->query->all(),
-            null !== $request ? $request : $this->request->all(),
-            null !== $attributes ? $attributes : $this->attributes->all(),
-            null !== $cookies ? $cookies : $this->cookies->all(),
-            null !== $files ? $files : $this->files->all(),
-            null !== $server ? $server : $this->server->all()
-        );
+        if ($query !== null) {
+               $dup->query = new ParameterBag($query);
+        }
+        if ($request !== null) {
+               $dup->request = new ParameterBag($request);
+        }
+        if ($attributes !== null) {
+          $dup->attributes = new ParameterBag($attributes);
+        }
+        if ($cookies !== null) {
+          $dup->cookies = new ParameterBag($cookies);
+        }
+        if ($files !== null) {
+               $dup->files = new FileBag($files);
+        }
+        if ($server !== null) {
+          $dup->server = new ServerBag($server);
+        }

         return $dup;
     }

Using initialize() after clone() overwrote all of the cloned members, so 
there was no real benefit from cloning?!

Regards,

Sven


-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to