Consolidate lambdas and method references in Collectors.java emul#10237
Consolidate lambdas and method references in Collectors.java emul#10237niloc132 wants to merge 5 commits intogwtproject:mainfrom
Conversation
|
Testing methodology: Ran test.web.htmlunit with package com.google.gwt.emultest.java17;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
com.google.gwt.emultest.java8.util.stream.CollectorsTest.class,
com.google.gwt.emultest.java9.util.stream.CollectorsTest.class,
com.google.gwt.emultest.java10.util.stream.CollectorsTest.class,
com.google.gwt.emultest.java17.util.stream.CollectorsTest.class,
})
public class CollectorsSuite {
}Enabling sourcemaps has the effect of disabling emulated stack trace mode for tests, which gives a more accurate picture of the size of the output. Running all existing CollectorsTest impls ensures that each method is called. cd user/
ant test.web.htmlunit '-Dgwt.junit.testcase.includes=**/CollectorsSuite.class' '-Dtest.args=-ea -sourceLevel auto -setProperty compiler.useSourceMaps=true'
ls -al ../build/out/user/test/web-htmlunit/www/com.google.gwt.emultest.EmulSuite.JUnit/*.cache.jsBefore: After: Savings of 1586 bytes. |
|
Looks good, though some parts may be redundant if #10160 gets implemented. |
|
Yeah I don't have super high hopes for #10160 - just keeping it focused on array creation and IntFunction at least narrows it a lot, but when you start to look at method references in general and all the various functional interfaces that could exist... plus how this might interact with incremental compilation, it has me a little worried. Maybe there could be a giant Interface+methodref lookup that dedups during optimization, but the method reference info itself is gone by then (GwtAstBuilder sees the actual method ref from JDT, but then creates plain classes out of it), so we'd have to add other metadata or redo parts of the gwt ast. Definitely not saying it can't be done (and it would be a great idea, should have more benefits beyond this), would definitely take a lot more work to get to this first 1.5kb than just manually deduping the method calls. |
Each lamdba or method reference results in a new "anonymous inner class" in GWT output. This patch deduplicates many of those to avoid multiple classes for a single purpose.
The joining() overloads have specific inner classes rather than multiple (two and four respectively) method references.
Partial #10207