[Kss-devel] ree-stripout-comments branch
Balazs Ree
ree at ree.hu
Mon May 7 11:05:48 CEST 2007
I created the ree-stripout-comment branch (should rather be called
stripout-asserts) which is an experiment with the technology of creating
a production and development version of the kss javascript.
We introduced the ;;; construct, if this appears in the beginning of a
line, the line will appear only in the development version and not in the
production version. The current code is marked this way and all logs,
exception messages and a lot of the asserts during parsing and binding
are now stripped. This results, in full compression mode, a 104K code
size, and compared to the current 129K this means a 19% win at the first
try. It may also be a bit faster, but I can't estimate this.
To use it with Plone, we need to again take the packing into our hands
from RR. All things have to be set up manually, as I did not want to
branch CMFPlone.
This is how to try it:
1. switch kss.core to the branch ree-stripout-comments
2. In portal_javascript tool, rename ++resource++kukit-src.js to
++resource++kukit.js, and enter the following condition into it:
here/@@kss_devel_mode/isoff
3. create a new resource like the previous one, with the name
++resource++kukit-devel.js with this condition:
here/@@kss_devel_mode/ison
or if you want, you can combine both of these conditions with the
current condition that disables kss for anonymous users, but this
is not important for testing.
So these are the two resources we have, and which one gets into the page,
is selected by the view.
It's all set up now. You can visit a simple UI at the browser page:
@@kss_devel_mode/ui
That shows you if kss is currently in production or in development mode.
You can toggle a browser cookie with the buttons. This is a client side
setting, no need to change the server for switching to development mode:
this is a very important principle imo. The setting can also be overruled
by RR: if you set debug mode in portal_javascript, kss will get into
development mode permanently and independently of the setting of the
cookie.
Something about the technology.
The ;;; construct works reasonable well, but it has some artifacts. I am
using the following patterns in the commentification:
;;; this line is only in development
This cannot be used however
- inside expressions that span multiple lines (like () or a string +)
- inside the switch statement
so I also used these:
/*
;;; */
this is only in development mode
and this too
;;; /*
*/
and even these:
;;; /*
this is only in production mode
and this too
;;; */
Comments, suggestions? I am open for new ideas. I agree ;;; does not work
so nice in some cases, but it's doable.
The stripout itself happens before the packer starts its job. This would
stay so, even if this gets integrated to the packer, we will need two
passes.
In the concatresource now you have the following packing levels available:
- none: the raw sources
- devel: like none but the ;;;-s themselves are removed
- prod: the production version unpacked, readable
- safe-devel: safe packing, devel version
- safe: safe packing of the production version
- full-devel: full packing, devel version
- full: full packing of the production version
Of these mostly devel, safe and full make sense. - At the moment only
kss's concatresource can pack this way, RR can not yet.
Please try this branch and see if you can notice any difference in
performance.
--
Balazs Ree
More information about the Kss-devel
mailing list