Remove stream usage from Symtab.lookupPackage()
Jonathan Gibbons
jonathan.gibbons at oracle.com
Wed Feb 22 18:15:29 UTC 2023
In times past, there were places in javac when `instanceof` was *not* a
substitute for checking the tag.
We've probably gotten rid of those cases by now, but as a general coding
pattern, I note that for end users writing code like annotation
processors, the problem still remains if using other compilers.
-- Jon
On 2/21/23 7:30 PM, Archie Cobbs wrote:
> On Tue, Feb 21, 2023 at 6:24 PM christoph.dreis at freenet.de
> <christoph.dreis at freenet.de> wrote:
>
> I'm currently profiling some compilation phases of internal
> projects and noticed in allocation profiles that
> |Symtab.lookupPackage| takes up ~2% overall. The majority of this
> is spent in |.stream().anyMatch()| usages to find out if the given
> module symbol depends on the unnamed module.
>
>
> Straightforward patch, but it's disappointing that unrolling a Stream
> into the equivalent for loop makes it noticeably faster (how much?).
>
> This also brings up larger philosophical questions about code style
> vs. performance. If using a Stream somewhere makes for more
> clean/elegant/understandable code, but is slower, how to weigh the
> trade-off? Maybe this has been discussed before on this list before I
> joined. Maybe we should assign this bug to the hotspot group :)
>
> On this same topic, this pattern which appears constantly in the
> compiler always makes me kind of quizzical:
>
> JCExpression expr = TreeInfo.skipParens(tree.expr);
> if (expr.hasTag(APPLY)) {
> JCMethodInvocation apply = (JCMethodInvocation)expr;
> ...
> }
>
> Is instanceof really that much slower? Maybe it was once, long ago,
> and this is a legacy thing?
>
> -Archie
>
> --
> Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230222/7b53cd6c/attachment-0001.htm>
More information about the compiler-dev
mailing list