Jan Obdržálek wrote:
OK - I still need to see the grammar really because the only reason I can think of that your run is producing nearly a million tree nodes, is that something isn't quite right. In the current release, when a subtree is rewritten in a higher rule, it is supposed to be copying the pointers and not creating new nodes. I can only think that it isn't doing that here.Hello, thank you very much for your help. Here are the answers. Parsing and pre-processing will take more time than compiling usually. If you optimize the code to death and include optimization time then there will be a lot more work being done, but code generation and related things should not be a large part of the time.Turning off the tree-building mechanism made all the difference - it saved about 80% of the running time. Being on par with gcc here (although we still need to remember that gcc does a full compilation) is quite a nice result for a generated parser. Of course :-) I spent a lot of time optimizing the tree building code in the current release - I don't think that there is anything inherently wrong with the mechanism, but I am beginning to think that something is causing way more nodes to be produced than should be. The constant, redundant rewriting of node streams is definitely an issue, but it should not be this big of an issue I think.<<< ~/tmp/test$ time ./parser Reading a.c real 0m0.481s user 0m0.360s sys 0m0.108sThe problem is I need the AST :( OK - Hmm, it shouldn't in theory and all my own tests said it was faster, but perhaps there is some optimization going on that means the function calls are being inlined (though as pointers to functions that seems unlikely) or generated very efficiently. There are various options of course, but the GUI allows you to view the results without the cycle getting in the way. Right - so your one function dealing with strings is 12% of the time (ignoring the tree stuff for the moment), rather than strcmp you should use memcmp, but it would be faster to use a TRIE. My general purpose hash map is convenient but when you are trying to squeeze optimal performance it might be slower than what you have (at least once you stop using strcmp) - give it a try though as hash maps are generally reasonable performers if sized correctly (the one I provide is not dynamic so you have to pick a modulo that is big enough up front). I provide int and int64 tries in the runtime, but I did not implement a string based version as I did not need it in the runtime - I always meant to come back and do that though.The profiling info in kcachegring after turning off the tree-building seems to be about what I expected. To give you the idea: 20.6% (inclusive time) mTokens[called 255 744 times] - this is the lexer part 12% (inclusive time) antlr3dfapredict - that's not too bad. I can definitely decrease this significantly. 12% (inclusive time) isTypeName [called 21 800 times] - this function checks whether the given identifier is a type name or not. It calls ~3 800 000 times strcmp (4.13%) That can also be improved. Also, in determining that something is a typedef, you obviously need the string that represents the typedef and the token. How are you gathering that? If you are using $text, then it will be much slower than it needs to be. Use the pointer to the token start and end/length - you should not even need to make a copy of it, just point directly into the source and store the length of it. The dfa prediction times can only really be improved if there is a better way to specify your lexer tokens than the way you are doing it. There may not be. But basically, most of the time otherwise being in the lexer is what you would expect. Yeah - but the tree building should not be taking up this amount of time - it could be just that that is how the code is currently generated, but I am not convinced - I need the grammar - perhaps you can send me a copy privately before you publish it.Sure, I'm not expecting miracles :) That time without the tree-building seems reasonable to me. Yes - I need to work out what is going wrong performance wise there. Do you happen to know how many node are in the final tree?To sum up - the main culprit is the tree-building mechanism. Other than that the performance of the generated parser is quite reasonable. The problem is that tree-building/rewriting capabilities of ANTLR are the main reason why we use ANTLR. Except for startup time, there is no way around that. However I think that for tasks like this Java is never going be close to the C target and while it is true that Sun's JIT can beat C in a lot of things such as branching, there are design patterns in C that you just cannot do in Java and generally that will be the biggest time difference. There is too much overhead in object creation and method calls. Apart from the startup time for Java being a huge problem for utilities like this (a long running application probably doesn't care that much - I have got used to the 15 second startup time for Netbeans on my QX9660 ;-), the inability to lay down static code that is set out at compile time means that the Java target has to uncompress the data for DFA tables before it even gets going.Second - I need (or would prefer) a fast Java target. Java does not have to be much slower than C. By all means tell us your results. In general I have found that parsing without tree building can get to be about half as fast as the C, so long as you take out the startup time. However, when you take out the time spent reading the source files (which is going to be about the same overhead for both), you find the difference is quite marked.If Java is that much slower, we will probably end up using C target for the parser and then translating the AST into a Java structure ... I will turn off the tree-building in Java and see what happens. If the time for Java without tree building is a lot less, then it tends to indicate that the inefficiency is in the generated code for tree node streams, which as Ter has already indicated, needs some optimization work in terms of removing the generation of code that is redundant. Jim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~--- |
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
