Bug 109 - [Chameleon] Code Review - WidgetManager.php
: [Chameleon] Code Review - WidgetManager.php
Status: RESOLVED FIXED
: Chameleon
Core
: 1.99
: All All
: P3 normal
: 2.0 RC 1
Assigned To:
:
:
: CodeReview
:
:
  Show dependency treegraph
 
Reported: 2003-11-13 07:21 by
Modified: 2004-12-20 15:10 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2003-11-13 07:21:20
Code Review for WidgetManager.php

scheduled for 2003-11-13, 10 AM.

Paul, Daniel, Zak, Julien
------- Comment #1 From 2003-11-13 11:37:43 -------
WidgetManager.php version 1.25 2003-10-31

- expand class comment to include better explanation of what the widget manager
actually does, include example, clarify that this is internal to Chameleon.
- add comments to class variables
- constructor needs comments
- investigate if foreach is faster than for?  If not, replace foreach with for.
- change " to '
- remove pre-registration of widgets from constructor, only build widget
directory array.
- in LoadWidget, test to see if the widget is loaded and if not, test for widget
in each directory, load it, and register that it is loaded.  Use class_exists()
- LoadWidget needs function comment
- is PreloadWidgets required?
- missing function description for CreateWidgetUsingTag, remove @param szContent
- add brackets to else on line 153
- line 127 - remove if, not required
- replace ExtractClassName with preg match?  Make sure that type="..." has a
space at the beginning. (Julien)
- check eval to see if it is causing a time problem (in CreateWidgetUsingTag)
- remove lines 155-159 (handled in Widget.php)
- 
------- Comment #2 From 2003-11-13 23:43:25 -------
class comment done
class variable comments done
constructor comments added
removed need for loop entirely
changed " for ' where practical, still require a regexp for finding widget type
to remove last one
removed pre-registration of widgets
modified LoadWidget to use class_exists and include in much tighter loop
added function comment to LoadWidget
removed PreloadWidgets
added function comment to CreateWidgetUsingTag, removed szContext
bracketed 'else'
eval is not a performance hit (AFAI can tell)
removed visibility code

outstanding is the preg_match function for getting the type name out.

BTW, include does not seem much faster than include_once ... this module is
still performance bound by the number/size of files it has to include rather
than any other factor.  For a reasonably complete template with 50-60 widgets,
this takes about 115 ms.
------- Comment #3 From 2003-11-14 11:03:45 -------
> eval is not a performance hit (AFAI can tell)

Ok, but I had made test (5 line script) before I got your comment. Here's the
result.
Eval can takes something like 3 times the normal time to execute simple calls,
but since we only do 50-60 class declaration call we probably only loss 1 millisec.

On a loop of 50 element that declare a "ttt" class each time, it takes 2
millisec  instead of 1 to do it with an eval() call.

I also found that instead of:

$szEval = "\$oWidget =& new $szClass();";
eval($szEval);

you can do:

$oWidget =& new $szClass;

It will declare a class with the name in $szClass

I don't know if it worth the change in the WigetManager.php file, but I feel
that it's good to know for everyone. Maybe Paul can make the change to see which
impact it has on his test when he profile it.
------- Comment #4 From 2003-11-18 11:52:22 -------
given the limited number of times it is run, I expect little gain, but this is
all about small improvements adding up.  I will make this change.  I believe
that it may be more useful in MapLab, which also uses this technique.
------- Comment #5 From 2004-04-05 16:27:43 -------
need to finish the changes in here for 1.99
------- Comment #6 From 2004-04-08 08:35:10 -------
updated version to 1.99
------- Comment #7 From 2004-05-03 10:26:17 -------
Changed Target Milestone to 1.99 RC
------- Comment #8 From 2004-12-20 13:56:36 -------
this is as done as I want to make it.  The final performance enhancement is
negligible and hopefully unnecessary if we build a php module (WidgetManager
would be one of the things replaced).
------- Comment #9 From 2004-12-20 15:10:35 -------
forgot to mark fixed.