Change bargull-20110317-tSC by bargull@Bargull02 on 2011-03-17 15:36:51
in /home/anba/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: improve compilation time for dhtml

New Features: LPP-9833 (speed up compilation time for dhtml)

Technical Reviewer: hqm
QA Reviewer: max
Doc Reviewer: (pending)

Overview:
By using Java VisualVM to profile the compilation time of the amazon-demo in dhtml-mode, I've found a couple of hot spots which needed too much time. With this change those hot spots should require less time or even be removed completely.
#1 issue:
To read out the bounds of an image, DHTMLWriter used the superclass method from ObjectWriter, but ObjectWriter simply transcoded the image to swf and then used the jgenerator API to get the bounds. So this was really a time consuming operation only to find out the image's size and the transcoded swf wasn't even used anymore later since we're compiling to dhtml.
#2 issue:
ImageMontageMaker used Thread.sleep() to wait for an image to load, overall this led to about 1600ms of pure waiting time on my computer.
#3 issue:
Calling File#getCanonicalFile() is expensive (at least on Windows), but it's used multiple times in DefaultFileResolver#resolveInternal(), even for non-existing files. (Canonical files are necessary because the file is later stored in a HashSet)

The other changes are extra improvements, but not linked to the named hot spots.


Details:
ImageMontageMaker:
- use MediaTracker to track image loading instead of periodically checking the image's width

ImageHelper:
- helper class to return the size of an image

ObjectWriter:
- split getResource(String,String,boolean) in several methods to improve modularity -- getAndCheckMimeType() returns the mime-type of the input, may throw an error if the mime-type is unsupported -- createResourceInfoElement() returns a jdom.Element for the resource to collect resource information -- importImage() transcodes the input image to swf and returns the Resource object

ObjectWriter.Resource:
- added getBounds() method to return the resource's bounds, either from the FlashDef if available, otherwise from the width/height properties
- getBounds() returns the bounds in TWIP units for backward compatibility

DHTMLWriter:
#importResource(File,String,Offset2D)
-- use Resource#getBounds() instead of accessing the resource's FlashDef which may be null
-- use constants instead of magic numbers
#importImage(String,String,String,boolean)
-- override superclass method to avoid transcoding the image to swf if possible

FileResolver:
- only call File#getCanonicalFile() when necessary



ViewSchema:
- removed isMouseEventAttribute() in favour of containsMouseEventAttribute()
- this may only result in an almost negligible improvement, but well it's there so why not

NodeModel:
- use containsMouseEventAttribute()

CompilerUtils:
- remove recursion and replace with plain iteration

Parser:
- removed xmltostring() and expandChildrenIncludes(), both methods aren't used anywhere
#readExpanded(File,Set,CompilationEnvironment)
- don't copy the hashset for every round, just add the current file and remove it later again
#evaluateSwitchStatement(Element,CompilationEnvironment)
- use emptyList() instead of returning a new, empty ArrayList
#expandIncludes(Element,Set,CompilationEnvironment)
- the method copied the element's children two times only to avoid ConcurrentModificationError - this was necessary because Element#getChildren() only returns a view on Element#getContent() - directly accessing and modifying Element#getContent() doesn't need any copies, so that's clearly a better choice - all ancestorIsDataSet() calls can simply be removed if you don't descend into dataset elements in the first place


Tests:
profile application with visualvm, see snapshots at bug report
run amazon demo in dhtml
smokecheck x {swf10,dhtml}

Files:
M WEB-INF/lps/server/src/org/openlaszlo/media/ImageMontageMaker.java
A WEB-INF/lps/server/src/org/openlaszlo/media/ImageHelper.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/ObjectWriter.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/DHTMLWriter.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/ViewSchema.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/FileResolver.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilerUtils.java
M WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java

Changeset: http://svn.openlaszlo.org/openlaszlo/patches/bargull-20110317-tSC.tar

Reply via email to