deduplicating lambda methods

Liam Miller-Cushon cushon at
Sat Mar 3 01:03:36 UTC 2018


I'm interested in adding support for deduplicating lambda methods to javac.
The idea is that if a compilation unit contains two lambdas that are
identical (including any captured state and the functional interface they
implement) we could re-use the same implementation method for both.

I understand there might have been some prior discussion about this. Is
there interest in investigating the feature? What sort of technical
considerations have been identified so far?

I have been thinking about a couple of questions:

1) How to identifying duplicates: I have a prototype that runs during
lambda desugaring and identifies duplicates by diffing ASTs. Is that the
best place for deduplication, or it worth considering comparing generated
code instead of ASTs?

2) Debug info: the optimization is safe if line numbers are not being
emitted. If they are, is there a way to deduplicate the methods without
breaking debug info?


More information about the amber-dev mailing list