-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Optimize Scannable#name()
and related logic
#3901
base: main
Are you sure you want to change the base?
Changes from all commits
518d059
a67e27c
c3e519a
6f7d079
7c8ce7b
02fa17e
36b3845
9cef75f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2024 VMware Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.core.publisher; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Fork(value = 1) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
public class TracesBenchmark { | ||
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The configuration and setup for this benchmark match those of the existing benchmarks, including explicit specification of default parameters. Can be cleaned up a bit more if desired. As for the impact of this PR, the following shows the before- and after output of Before:
After
Note how performance of the new implementation is almost independent of the input, while the old implementation scales fairly poorly. |
||
@Param({"0", "1", "2"}) | ||
private int reactorLeadingLines; | ||
|
||
@Param({"0", "1", "2"}) | ||
private int trailingLines; | ||
|
||
private String stackTrace; | ||
|
||
@Setup(Level.Iteration) | ||
public void setup() { | ||
stackTrace = createStackTrace(reactorLeadingLines, trailingLines); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@Benchmark | ||
public String measureThroughput() { | ||
return Traces.extractOperatorAssemblyInformation(stackTrace); | ||
} | ||
|
||
private static String createStackTrace(int reactorLeadingLines, int trailingLines) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < reactorLeadingLines; i++) { | ||
sb.append("\tat reactor.core.publisher.Flux.someOperation(Flux.java:42)\n"); | ||
} | ||
sb.append("\tat some.user.package.SomeUserClass.someOperation(SomeUserClass.java:1234)\n"); | ||
for (int i = 0; i < trailingLines; i++) { | ||
sb.append("\tat any.package.AnyClass.anyOperation(AnyClass.java:1)\n"); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in
MonoCallableBenchmark
: as stated, these are unrelated improvements. Can be pulled into a separate PR if desired.