JS document.xxx is really slow
David Faure
david at mandrakesoft.com
Sat Nov 16 00:05:57 GMT 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Saturday 16 November 2002 00:35, Koos Vriezen wrote:
> I get a time of 3.7 on a P4 2.4 GHz. One of the causes is that the DOM
> tree is search three times for each document.xxx,
> document.images/forms/applets (used to be document.all which was three
> times faster).
Indeed. My plan was to make things work for 3.1, and to make them fast after it :)
The idea Dirk and I have been toying with for quite some time now, is a
cache (map) within khtml, which associates nodes with strings (id or name, with
a way to know which one matches (or if both do)). The main problem with
that idea being to update the cache during parsing and dynamic changes,
and also to create it on demand (no use making such a cache if there's no JS
on the page at all).
Anyway, this is not for 3.1. Your patch is a good short-term solution before
khtml gets such a global cache.
> I've attached a patch that makes it an one times scan again. It also
> caches the node in case one is found. With it the time is 1.8 seconds,
> that's about twice as fast.
Excellent.
> Note, this patch does change preference for applets before frames (which
> was the other way around) but can be changed easily if needed.
I didn't test this particular preference order (since applets were added afterwards).
About the patch: some namings are a bit confusing, e.g.
TagLength has a length attribute, but NamedTagLengthDeterminer has one too
(which is in fact 3, the number of tags to look for - can you call that one numberOfTags or nrTags?)
In fact I would even suggest that a private helper method might be enough for
this, an actual separate class isn't necessary (since it's created/destroyed each
time). The private member vars would become the local vars of the private method.
Well, that's just nitpicking for code readability, I hope you'll forgive me for that :)
Feel free to apply whichever variant (btw some comments need to be moved, etc.).
- --
David FAURE, david at mandrakesoft.com, faure at kde.org
http://people.mandrakesoft.com/~david/
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE91Yvl72KcVAmwbhARAt5YAJ9RdS0vM0zmQLGK+LNrPXL1ww8JrwCfY5Gv
8YEOlXJl6cXBlYCWjfPzrg4=
=8+SM
-----END PGP SIGNATURE-----
More information about the kfm-devel
mailing list