forked from zio/zio-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Micro-optimizations and improved
IOException
error handling (zio#2638)
* Micro-optimizations and fixes * Fix `CharSequenceExtensions.compare` method
- Loading branch information
1 parent
842af96
commit 49d4aa4
Showing
5 changed files
with
107 additions
and
158 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
zio-http-benchmarks/src/main/scala/zhttp.benchmarks/UtilBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package zio.http.netty.benchmarks | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import zio.http.internal.{CaseMode, CharSequenceExtensions} | ||
import zio.http.netty.model.Conversions | ||
|
||
import io.netty.handler.codec.http.DefaultHttpHeaders | ||
import org.openjdk.jmh.annotations._ | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Fork(1) | ||
@Warmup(iterations = 3, time = 3) | ||
@Measurement(iterations = 3, time = 3) | ||
class UtilBenchmark { | ||
|
||
private val nettyHeaders = | ||
new DefaultHttpHeaders() | ||
.add("Content-Type", "application/json; charset=utf-8") | ||
.add("Content-Length", "100") | ||
.add("Content-Encoding", "gzip") | ||
.add("Accept", "application/json") | ||
.add("Accept-Encoding", "gzip, deflate, br") | ||
.add("Accept-Language", "en-US,en;q=0.9") | ||
.add("Connection", "keep-alive") | ||
.add("Host", "localhost:8080") | ||
.add("Origin", "http://localhost:8080") | ||
.add("Referer", "http://localhost:8080/") | ||
.add("Sec-Fetch-Dest", "empty") | ||
.add("Sec-Fetch-Mode", "cors") | ||
.add("Sec-Fetch-Site", "same-origin") | ||
.add( | ||
"User-Agent", | ||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/88.0.4324.96 Chrome/88.0.4324.96 Safari/537.36", | ||
) | ||
|
||
private val headers = Conversions.headersFromNetty(nettyHeaders) | ||
|
||
@Benchmark | ||
def benchmarkEqualsInsensitive(): Unit = { | ||
CharSequenceExtensions.equals( | ||
"application/json; charset=utf-8", | ||
"Application/json; charset=utf-8", | ||
caseMode = CaseMode.Insensitive, | ||
) | ||
() | ||
} | ||
|
||
@Benchmark | ||
// For comparison with benchmarkEqualsInsensitive | ||
def benchmarkEqualsInsensitiveJava(): Unit = { | ||
val _ = "application/json; charset=utf-8".equalsIgnoreCase("application/json; Charset=utf-8") | ||
() | ||
} | ||
|
||
@Benchmark | ||
def benchmarkHeaderGetUnsafe(): Unit = { | ||
headers.getUnsafe("sec-fetch-site") | ||
() | ||
} | ||
|
||
@Benchmark | ||
def benchmarkStatusToNetty(): Unit = { | ||
Conversions.statusToNetty(zio.http.Status.InternalServerError) | ||
() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters