-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the performance of failed semantic predicate #53
Comments
I completed a performance experiment, which is not very strict. Without filling stack trace: package stacktrace;
public class MyException extends RuntimeException {
public MyException(String msg) {
super(msg);
}
public synchronized Throwable fillInStackTrace() {
return this;
}
public static void main(String[] args) {
long b = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
try {
throw new MyException("hello");
} catch (MyException e) {
}
}
long e = System.currentTimeMillis();
System.out.println("## " + (e - b) + "ms");
}
} |
The following code costs about 80ms on my local machine. With filling stack trace: package stacktrace;
public class MyException extends RuntimeException {
public MyException(String msg) {
super(msg);
}
// public synchronized Throwable fillInStackTrace() {
// return this;
// }
public static void main(String[] args) {
long b = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
try {
throw new MyException("hello");
} catch (MyException e) {
}
}
long e = System.currentTimeMillis();
System.out.println("## " + (e - b) + "ms");
}
} |
As you can see, about 75% time can be saved. |
I'll submit a PR later :-) |
daniellansun
changed the title
Improve the performance of semantic predicate
Improve the performance of failed semantic predicate
Aug 10, 2019
sharwell
added a commit
that referenced
this issue
Oct 9, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Background
When semantic predicate fails,
FailedPredicateException
will be thrown to change the control flow. But as we all know, filling the stack trace is expensive especially whenFailedPredicateException
is thrown frequently.Proposal
I propose to override
fillInStackTrace()
ofFailedPredicateException
, and its implementation is simplified as follows:its default implementation is:
Advantages & Disadvantages
FailedPredicateException
, but usually we do not care about its stack trace.If we want to address
FailedPredicateException
some day, we can add the state to the exception message, e.g.The text was updated successfully, but these errors were encountered: