How would I optimize this parser?

T.D.Spenser thoughdispenser.org at gmail.com
Sun Oct 31 17:28:29 PDT 2010


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> T.D.Spenser:
> > Unfortunately, it's quite slow. Can anyone point out what might be the issue(s)?
> Very good :-)
> First suggestions:
> - Generally compile your D code using the -w switch (you have missing some
overrides and more things)
> - Add a main() with some benchmarking examples to your program, so I will have
something to optimize for.
> - Use the -profile compiler switch on the benchmarking examples to see what's slow.
> - Use final classes or final methods where possible and keep an eye on memory
allocations. Consider using structs in some places instead of classes.
> - Keep in mind that ~ and ~= in arrays isn't a very fast operation. In some
cases an Appender helps, and in some cases some workaround may be needed.
> See you later,
> bearophile

Thanks for replying.

Here is a version with a main function and sample file to parse:

http://thoughtdispenser.net/files/parser-test.7z

I fixed the warnings, but didn't change anything else yet.

Having built-in profiler is nice, I didn't know about it. Although, the files it
spits out are quite strange. If I read them right, it seems the parser spends most
time constructing nodes for the document's object model.


More information about the Digitalmars-d-learn mailing list