-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Christoph Dreis opened SPR-14624 and commented
Hey,
I just noticed a rather costly assertion in the websocket layer - more explicitly in StompSubProtocolHandler.convertConnectAcktoStompConnected().
As the framework is now using Java 8 features, I wanted to add methods in Assert that can make use of suppliers. But you already did that ;-)
So I just used the new methods in an isolated test for a benchmark and the results show a crazy factor of 4300. I might be tricked by dead code elimination or some other compiler voodoo, because I don't trust those results.
@BenchmarkMode(Mode.Throughput)
@State(Scope.Thread)
public class MyBenchmark {
@State(Scope.Thread)
public static class TestState {
public String testObject = "a";
public StompHeaderAccessor headerAccessor;
public TestState() {
MultiValueMap<String, String> extHeaders = new LinkedMultiValueMap<>();
extHeaders.add(StompHeaderAccessor.STOMP_LOGIN_HEADER, "joe");
extHeaders.add(StompHeaderAccessor.STOMP_PASSCODE_HEADER, "joe123");
headerAccessor = StompHeaderAccessor.create(StompCommand.CONNECT, extHeaders);
}
}
@Benchmark
public void testAssertNormal(TestState testState) {
for (int i = 0; i < 1000; i++) {
Assert.notNull(testState.testObject, "Original STOMP CONNECT not found in " + testState.headerAccessor);
}
}
@Benchmark
public void testAssertSupplier(TestState testState) {
for (int i = 0; i < 1000; i++) {
Assert.notNull(testState.testObject, () -> "Original STOMP CONNECT not found in " + testState.headerAccessor);
}
}
}| Benchmark | Mode | Cnt | Score | Error | Units |
|---|---|---|---|---|---|
| MyBenchmark.testAssertNormal | thrpt | 30 | 966,149 | 12,945 | ops/s |
| MyBenchmark.testAssertSupplier | thrpt | 30 | 4194886,453 | 72553,850 | ops/s |
Nevertheless, I changed the code to use the supplier methods in the attached PR.
Unfortunately, this will be only available in 5.x so I would appreciate a solution for 4.x that avoids the apparently rather costly assertion/string-concatenation of StompHeaderAccessor instances.
Best,
Christoph
Affects: 4.2.7, 4.3.2
Reference URL: #1138
Issue Links:
- Fix assertions in StompHeaderAccessor [SPR-14625] #19192 Fix assertions in StompHeaderAccessor
- Improve performance of StompCommand.getMessageType() [SPR-14636] #19203 Improve performance of StompCommand.getMessageType()
- Improve performance of StompEncoder.encode() [SPR-14747] #19313 Improve performance of StompEncoder.encode()
Referenced from: commits 0735e9b, 3811a59, 56b197b
Backported to: 4.2.8