-
Notifications
You must be signed in to change notification settings - Fork 421
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
Micro-optimizations and improved IOException
error handling
#2638
Changes from all commits
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 @@ | ||
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) | ||
() | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ object Status { | |
Try(code.toInt).toOption.map(fromInt) | ||
|
||
def fromInt(code: Int): Status = { | ||
code match { | ||
(code: @annotation.switch) match { | ||
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. Just for me: Is this an optional hint? Might the compiler create a switch without it? Might the compiler not create a switch with it? 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.
Yes
No This is very similar to 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. Thx! 👍 |
||
case 100 => Status.Continue | ||
case 101 => Status.SwitchingProtocols | ||
case 102 => Status.Processing | ||
|
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.
Love this change 👍