Skip to content
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 statusLine and StatusMessage by using slice instead of map #855

Merged
merged 4 commits into from
Aug 2, 2020
Merged

improve statusLine and StatusMessage by using slice instead of map #855

merged 4 commits into from
Aug 2, 2020

Conversation

kiyonlin
Copy link
Contributor

We use slice instead of map to store all status messages and status lines. But for the status code bigger than statusMessageMax(511), it still should store them in the dynamic map(invalidStatusLines).

@erikdubbelboer PTAL

benchmarks result:
OLD:

BenchmarkStatusLine99
BenchmarkStatusLine99-8         278959663                4.51 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         262258332                4.83 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         257144448                4.73 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         251641419                4.80 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200
BenchmarkStatusLine200-8        257207306                4.64 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        257618150                4.71 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        251996420                4.75 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        252930247                4.79 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512
BenchmarkStatusLine512-8        222729294                5.49 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        218682082                5.43 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        218821902                5.48 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        219236438                5.62 ns/op            0 B/op          0 allocs/op

NEW:

BenchmarkStatusLine99
BenchmarkStatusLine99-8         545864635                2.22 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         517671476                2.33 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         505288328                2.31 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine99-8         505923718                2.36 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200
BenchmarkStatusLine200-8        534919548                2.20 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        538629565                2.25 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        523182661                2.30 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine200-8        515232004                2.27 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512
BenchmarkStatusLine512-8        223080207                5.42 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        222268503                5.39 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        216794157                5.47 ns/op            0 B/op          0 allocs/op
BenchmarkStatusLine512-8        216436990                5.57 ns/op            0 B/op          0 allocs/op

Co-authored-by: Fenny fenny@gofiber.io
Co-authored-by: ReneWerner87 rene@gofiber.io

kiyonlin and others added 2 commits July 28, 2020 20:23
Co-authored-by: Fenny <fenny@gofiber.io>
Co-authored-by: ReneWerner87 <rene@gofiber.io>
@erikdubbelboer
Copy link
Collaborator

Thanks for the PR. I'm looking at this code now and to be honest I think we shouldn't keep invalid status codes in memory. Those shouldn't really happen often enough for this to be worth it (the memory and the code complexity). Can you make invalidStatusLine() just return the formatted line and remove invalidStatusLines? Thanks.

status.go Outdated Show resolved Hide resolved
@erikdubbelboer erikdubbelboer merged commit 2509c12 into valyala:master Aug 2, 2020
@erikdubbelboer
Copy link
Collaborator

Thanks!

@kiyonlin kiyonlin deleted the improve-status-line branch August 2, 2020 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants