atom feed40 messages in org.codehaus.groovy.userRe: [groovy-user] Acceptable Placemen...
FromSent OnAttachments
Randall R SchulzDec 3, 2007 3:41 pm 
Stand TrooperDec 3, 2007 4:03 pm 
Randall R SchulzDec 3, 2007 4:07 pm 
Stand TrooperDec 3, 2007 4:34 pm 
Russel WinderDec 3, 2007 9:46 pm 
Russel WinderDec 3, 2007 9:49 pm 
Charles Oliver NutterDec 3, 2007 9:52 pm 
Randall R SchulzDec 3, 2007 10:10 pm 
Jochen TheodorouDec 4, 2007 5:59 am 
Charles Oliver NutterDec 4, 2007 10:59 am 
Jochen TheodorouDec 4, 2007 11:51 am 
Smith, Jason, CTR, OASD(HA)/TMADec 4, 2007 1:10 pm 
Charles Oliver NutterDec 4, 2007 1:24 pm 
Charles Oliver NutterDec 4, 2007 1:29 pm 
Jochen TheodorouDec 4, 2007 1:54 pm 
Smith, Jason, CTR, OASD(HA)/TMADec 4, 2007 2:33 pm 
Jochen TheodorouDec 4, 2007 2:44 pm 
Charles Oliver NutterDec 4, 2007 2:56 pm 
Smith, Jason, CTR, OASD(HA)/TMADec 5, 2007 6:35 am 
Charles Oliver NutterDec 5, 2007 10:16 am 
Smith, Jason, CTR, OASD(HA)/TMADec 5, 2007 10:29 am 
Jochen TheodorouDec 5, 2007 5:45 pm 
Jochen TheodorouDec 7, 2007 8:31 am 
Randall R SchulzDec 7, 2007 8:37 am 
Jochen TheodorouDec 7, 2007 8:49 am 
Guillaume LaforgeDec 7, 2007 9:01 am 
Jochen TheodorouDec 7, 2007 9:14 am 
Guillaume LaforgeDec 7, 2007 9:16 am 
Randall R SchulzDec 7, 2007 9:22 am 
Guillaume LaforgeDec 7, 2007 9:28 am 
Charles Oliver NutterDec 7, 2007 10:09 am 
Charles Oliver NutterDec 7, 2007 10:11 am 
Randall R SchulzDec 7, 2007 10:18 am 
Jochen TheodorouDec 7, 2007 10:31 am 
Charles Oliver NutterDec 7, 2007 12:23 pm 
Randall R SchulzDec 7, 2007 12:37 pm 
Charles Oliver NutterDec 7, 2007 1:35 pm 
Randall R SchulzDec 7, 2007 1:40 pm 
Gavin GroverDec 7, 2007 11:49 pm 
Jochen TheodorouDec 8, 2007 3:40 am 
Subject:Re: [groovy-user] Acceptable Placement of default: Within Switch?
From:Jochen Theodorou (blac@gmx.org)
Date:Dec 4, 2007 2:44:47 pm
List:org.codehaus.groovy.user

Charles Oliver Nutter schrieb:

Smith, Jason, CTR, OASD(HA)/TMA wrote: [...]

why can't you do some optimizations when they're valid and not when not?

what means valid? If I add so much optimizations that the compiler will run ten times slower then it is still valid, but not desired. For example I could add dynamic branch prediction to my if-else-cascade, that is possibly much faster if the values do not change too much. Hotspot could do something like that for example, not sure if it does.

I don't understand why you'd only compile it one way--the slowest possible way--when there's a valid alternative for many constant cases. Even Java compiles switches two different ways depending on case density.

I know, why do you think I was talking about tableswitch and lookupswitch? But just because there is bytecode for this, does not mean it was good to do so. Let me just name the JSR instruction as an example. It just looks good on the paper, that's all.

And when you say the slowest way... That is not valid fact unless you provide a testcase showing this. and the only thing I can imagine this could be important (and microbenchamrks do not count here) is a lexer as I already mentioned. But you would write a lexer in Groovy different from Java... for example you would have this in java:

case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':

but this in Groovy:

case '0'..'9'

so you make one case statement where you had ten before. Let us do a little counting in GroovyLexer.java. I find

#cases: #places: 2 7 3 2 4 3 (1 as 1 range) 5 2 6 3 (2 as 3 ranges) 7 1 10 1 (1 with 2 ranges) 12 1 (1 with 3 ranges) 18 1 22 1 (1 as 3 ranges) 30 1 64 1 (1 as one range) 87 1 (1 with 5 ranges)

that makes 27 switch constructions with an average of 11 cases. Which means we are far away form hundreds of cases for a switch. And if I replace some of these with ranges, then I get an average of 4 cases for my switch. the really nasty cases with 87 and 64 cases can be replaced, so the maximum number is reduced to 30.

But all this is not really important... important is which construct is visited how often, and here I don't have numbers.

So... of course Groovy would gain much speed with such constructions in case of a lexer... that is if you write the Lexer in Java style. And I am not sure I would write the Lexer in the same style, even with using ranges as it is now if I had the abilities of Groovy. For example the Lexer uses BitSets, maybe I would use even more of them, then I get a massive reduction of the cases in many constructs. Maybe I would use a hash and closures instead at other places, then I get a big speedup again compared to a binary search. But certainly I would do something about that stupid NoViableAltForCharException, that costs so much performance in our.. ah, ok, thats the parser, not lexer ;)

I really think making our dynamic method calls faster is of a much higher priority than this. This doesn't mean we won't optimize this some time in the future, but atm there is no point in doing so.

bye blackdrag