Skip to content

Commit 76d3e74

Browse files
authored
Inferring type arguments is slow (#7125)
1 parent 3d9448e commit 76d3e74

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

docs/manual/faq.tex

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@
402402
\subsectionAndLabel{Will using the Checker Framework slow down my program? Will it slow down the compiler?}{faq-slowdown}
403403

404404
Using the Checker Framework has no impact on the execution of your program:
405-
the compiler emits the identical bytecodes as the javac
406-
compiler and so there is no run-time effect. Because there is no run-time
405+
the javac compiler emits identical bytecodes whether or not the Checker
406+
Framework is used, so there is no run-time effect. Because there is no run-time
407407
representation of type qualifiers, there is no way to use reflection to
408408
query the qualifier on a given object, though you can use reflection to
409409
examine a class/method/field declaration.
@@ -1816,11 +1816,11 @@
18161816
limit is so small that the Checker Framework might spend most of its time
18171817
in garbage collection. (If this is the case, the Checker Framework will
18181818
issue a warning ``Garbage collection consumed over 25\% of CPU during the
1819-
past minute.") For example, you might pass an argument like
1820-
\<-Xmx3g>, or set an environment variable like \<export
1821-
\_JAVA\_OPTIONS=-Xmx3g>, to permit the Checker Framework to use up to 3GB
1822-
of memory. If you use Java 8, consider upgrading to Java 11 or Java 17, which have
1823-
better memory management.
1819+
past minute.") To permit the Checker Framework to use up to 3GB of
1820+
memory, pass an argument like \<-Xmx3g> or set an environment variable
1821+
like \<export \_JAVA\_OPTIONS=-Xmx3g>. Also consider upgrading to a more
1822+
recent release of Java, because older versions of Java (especially 8 and
1823+
11, but also 17) have worse memory management.
18241824
\item
18251825
Set your build system to perform \emph{incremental compilation}. When
18261826
compiling just a few source files (the size of a typical edit or commit),
@@ -1832,6 +1832,13 @@
18321832
uses Maven, consider switching to a more capable build system such as Gradle.)
18331833
% (Note that some build systems have a bug, in that they unnecessarily always
18341834
% re-run compilation that uses annotation processors.)
1835+
\item
1836+
Write generic type arguments. Often, generic type inference is the
1837+
slowest part of type-checking. You can significantly speed up
1838+
type-checking by explicitly writing a few generic type arguments. To
1839+
determine where to write them, temporarily set
1840+
\<-AslowTypecheckingSeconds> to a small value, such as 1. Write type
1841+
arguments where \<slow.typechecking> warnings are issued.
18351842
\end{itemize}
18361843
18371844
If the Checker Framework is still too slow for you to run on every compilation,

docs/manual/introduction.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@
814814
\<-AslowTypecheckingSeconds=N>
815815
Print a warning for any program construct, such as a method or class, whose
816816
type-checking takes more than N seconds (default 45).
817+
Often, generic type inference is the slowest part of type-checking, and you
818+
can significantly speed up type-checking by explicitly writing a few
819+
generic type arguments.
817820

818821
\item
819822
\<-Aversion>

framework/src/main/java/org/checkerframework/common/basetype/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ redundant.anno=Annotation %s is redundant: it's the same as the default at this
126126

127127
type.inference.failed=type inference crashed: %s
128128

129-
slow.typechecking=typechecking took %d seconds
129+
slow.typechecking=typechecking took %d seconds; consider making inferred type variables explicit

0 commit comments

Comments
 (0)