eisop / checker-framework

Pluggable type-checking for Java
https://eisop.github.io/
Other
17 stars 16 forks source link

Improve performance of `var` variable declarations #657

Closed wmdietl closed 7 months ago

wmdietl commented 7 months ago

Some timing:

Before this PR:

After this PR:

There is still a large difference between using var and using Object, which we should investigate more.

typetools, at https://github.com/typetools/checker-framework/commit/f58c9d93d562c923d2fea17fec978eb2b8040858 (commit before https://github.com/typetools/checker-framework/commit/dc0e62c36818cf76762a4357bbb597d559cbbb28):

typetools, at https://github.com/typetools/checker-framework/commit/dc0e62c36818cf76762a4357bbb597d559cbbb28:

typetools, at https://github.com/typetools/checker-framework/commit/ccec69e53393e3c6dbbbc7bc53f8ad60be6fd679 (this test case crashes on typetools HEAD):

So, this PR gets eisop in line with typetools (which is good, given eisop splits init and nullness), but doesn't undo the performance hit from improved var support.

Co-authored-by: Liam Miller-Cushon cushon@google.com

wmdietl commented 7 months ago

@flo2702 Can you have a look at the performance difference between using the Initialization Checker and disabling it? Maybe you see something else that impacts performance?

wmdietl commented 7 months ago

The newest changes in https://github.com/eisop/checker-framework/pull/657/commits/6109041c90ead352793e497da2ad6f21465c2ad3 re-enable caching in getAnnotatedTypeLhs for variables declared using var. This only has an effect on the initializer expression, avoiding that its type is re-computed multiple times. The expanded tests in https://github.com/eisop/checker-framework/pull/657/commits/43babac00e8dd80ec94234195c8bae36da3b22c7 make sure that re-assignment to such a variable doesn't cause re-computation.

With initialization, using both Object and var, the time is now roughly equal, at around 45s.