If I add a check for an option, and make this routine a no-op, is it
going to work, or break something? Alternatively, I can replace calls
to canCastUnsafe/dynamicCast with no-ops further down in the
processing and get rid of all casts.
I think it's more like no one's brain is large enough to keep full
cognition of 3 complete AST APIs concurrently, and the GWT team lacks
resources to have a guy who's sole purpose is to own JDT->GwtAST.
Looking at the comments, the JDT AST isn't exactly a pleasure to work
with either. There's comments in the source for non-obvious stuff, but
it still requires indepth understanding of JDT, and I don't know if I
have enough brain cells to spare. :)
Scott's brain on the other hand is a different story. You'll note from
photos his skull is about 20% larger than the average persons. :)
I see two general strategies that would get the info on casts:
1. Modify CastNormalizer to simply removes all casts, and see what the
size difference is. This behavior would ultimately be settable by a
flag, assuming it actually gets a significant size improvement.
2. Have a flag in JCast named "alwaysSucceeds". Update CloneVisitor
accordingly. Update GenerateJavaAST to turn this on for generics
casts; it could be inserted for others as well. Update the cast
normalizers to check this flag. This is a setting that could be
enabled by default.
#2 is unsound as described, but is probably sound enough. :) I'd
guess it can only go wrong in places where an IDE would at least give
a warning, e.g. casting to a type parameter. We could iterate to a
better precise definition over time.
Regarding flags, giving each visitor a reference to the entire flag
set would add a lot to the dependencies of each visitor. If instead
they have a set of individual parameters, and JJS sets those
parameters, then only JJS has the heavy dependency. Fewer
dependencies is good. In theory we could unit test visitors in
isolation; the lighter the dependencies, the more plausible this is.
Besides, for doing experiments, it is just as well not to create a
flag. Simply comment in or out the relevant code and rerun the
compile.
Lex
This would be my preference actually, and not just for size, but for
performance. When I profile in Firefox, I see that
dynamicCast/canCastUnsafe have a huge number of invocations (easily in
the top 10 hotspots), as well as chewing up about 5-10% of total CPU.
Granted, my application is more intensive than most, but would
definitely be a welcome improvement. I can't see many apps deployed in
web-mode actually caring about accurate class cast exceptions, and
hopefully, most CCEs would be caught much easier in the development
process, in hosted mode, or during unit tests.
-Ray
That's higher than I realized. Certainly high enough to make a strong
argument for being a touch less safe to gain the speed.
Note, though, that we still don't know how many of those could be
removed if we had a "known to succeed" flag in JCast. It might be
that most of them are due to generics rather than to explicit casts
the user put in. In that case, the overhead might mostly go away
while giving up much less safety.
Lex