Re: Flow control by Exception
Jonathan Revusky <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Feb 5, 2009 at 10:37 PM, Bruce Ritchie <[email protected]> wrote: > Hi, > > I've been hunting down some performance issues in our application and > one of the things I noticed is that the FMParser/FMParserTokenManager > seems to do flow control by exception. In general that is never a good > idea but it can really impact performance in our application because > of our heavy reliance on FreeMarker for our display layer. > > To give an example, adding > > ${"1 + 2"?eval} to a template will guarantee that an IOException will > be created and thrown, caught and handled. I've annotated the > FMParserTokenManager to spit out any time an IOException is thrown and > here is a portion of the stack trace from adding the above call: > > java.io.IOException > at freemarker.core.SimpleCharStream.FillBuff(SimpleCharStream.java:111) > at freemarker.core.SimpleCharStream.readChar(SimpleCharStream.java:188) > at freemarker.core.SimpleCharStream.BeginToken(SimpleCharStream.java:129) > at freemarker.core.FMParserTokenManager.getNextToken(FMParserTokenManager.java:6430) > at freemarker.core.FMParser.jj_scan_token(FMParser.java:4577) > at freemarker.core.FMParser.jj_3_1(FMParser.java:3658) > at freemarker.core.FMParser.jj_2_1(FMParser.java:2967) > at freemarker.core.FMParser.PrimaryExpression(FMParser.java:268) > at freemarker.core.FMParser.UnaryExpression(FMParser.java:319) > at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:435) > at freemarker.core.FMParser.AdditiveExpression(FMParser.java:385) > at freemarker.core.FMParser.RangeExpression(FMParser.java:556) > at freemarker.core.FMParser.RelationalExpression(FMParser.java:511) > at freemarker.core.FMParser.EqualityExpression(FMParser.java:476) > at freemarker.core.FMParser.AndExpression(FMParser.java:585) > at freemarker.core.FMParser.OrExpression(FMParser.java:608) > at freemarker.core.FMParser.Expression(FMParser.java:221) > at freemarker.core.StringBuiltins$evalBI.calculateResult(StringBuiltins.java:169) > at freemarker.core.StringBuiltins$StringBuiltIn._getAsTemplateModel(StringBuiltins.java:71) > > > Note that this isn't isolate to ?eval - I swear an IOException or two > is thrown anytime a template is loaded, though not always from the > same place. Well, the eval and interpret built-ins are, I think, pretty clearly advertised as being on the costly side performance-wise... It reparses the string (i.e. mini-template) each time it is rendered -- as opposed to regular template processing, where the template is already pre-parsed into an AST when you render. > > I've also noticed that FMParser uses an exception LookaheadSuccess to > do exactly what the name implies. There is even a variable assigned to > it, unfortunately it's not static > > final private LookaheadSuccess jj_ls = new LookaheadSuccess(); The LookaheadSuccess thingy is something that any parser generated using JavaCC does. The current situation is that the parser in FM 2.3 is generated using JavaCC but FM 2.4 uses FreeCC ( see http://freecc.googlecode.com ) that is a fork of JavaCC (my fork... long story....). Anyway, FreeCC is where most of my open source hacking time is going now. I've been systematically addressing a lot of the warts in JavaCC. This one not yet.... I was aware of it, but other things had higher priority. OTOH, the squeaky wheel gets the grease, so you can suppose that I'll be having a look at this fairly soon. > > If it was static it at the very least wouldn't incur the > fillInStackTrace JVM call which is so painful performance wise - being > static isn't an issue in this case since this exception is never > rethrown as best as I can tell. Yes, that is probably quite easy to address and I'll have a look at that in FreeCC. But note that any improvements on this will only be for 2.4.x. It may be a while before you can (at least while applying proper caution) standardize on FM 2.4. The best you can do meanwhile, I guess, is to see if you can lessen your use of ?eval. > > Is the 2.4 FMParser going to be better about this? I think yes. Most probably... :-) > Can anything be > done for 2.3.x to help stop this performance impacting pattern (beyond > the hacks I've made to fix/workaround these issues). ? Hmm... I dunno. Probably not... :-( Now, for all I know, maybe Attila is going to jump up and say that he is going to do something. He is more inclined to put energy into 2.3. Just speaking for me, what energy I devote to hacking freemarker is going to go into getting the 2.4 branch into shape for a stable release. I just tend to think that whatever warts are in 2.3 (and there are plenty...) are basically there. And actually, aside from this issue, 2.4 really does address a lot of the shortcomings in 2.3. (Annoying issues wrt java nulls, cleaning up scopes and variable declaration, are just a couple of examples...) Most of that stuff has has been done for like a couple of years, but we really just need to get it stabilized and out there. Not a great project management story.... it's mostly my fault I know... :-( Regards, Jonathan > > > Regards, > > Bruce Ritchie > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com