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

chore(performance): Improve performance for adding RemoveExtraSlash flag #2159

Merged
merged 2 commits into from
Nov 28, 2019

Conversation

appleboy
Copy link
Member

See the detailed benchmark: #2153

before:

#GithubAPI Routes: 203
   Gin: 58512 Bytes

#GPlusAPI Routes: 13
   Gin: 4384 Bytes

#ParseAPI Routes: 26
   Gin: 7776 Bytes

#Static Routes: 157
   Gin: 34936 Bytes

goos: darwin
goarch: amd64
pkg: github.com/julienschmidt/go-http-routing-benchmark
BenchmarkGin_Param        	11682692	       107 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param5       	 5853684	       205 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param20      	 2497855	       484 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParamWrite   	 6599636	       180 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubStatic 	 9790374	       125 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubParam  	 4965781	       244 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubAll    	   24424	     49748 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusStatic  	14304789	        86.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusParam   	 6814308	       174 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlus2Params 	 4847437	       253 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusAll     	  504351	      2302 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseStatic  	12430803	        99.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseParam   	10323856	       119 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Parse2Params 	 7512644	       159 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseAll     	  305469	      3961 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_StaticAll    	   37492	     30986 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/julienschmidt/go-http-routing-benchmark	23.774s

after:

#GithubAPI Routes: 203
   Gin: 58512 Bytes

#GPlusAPI Routes: 13
   Gin: 4384 Bytes

#ParseAPI Routes: 26
   Gin: 7776 Bytes

#Static Routes: 157
   Gin: 34936 Bytes

goos: darwin
goarch: amd64
pkg: github.com/julienschmidt/go-http-routing-benchmark
BenchmarkGin_Param        	15443652	        78.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param5       	 9414763	       127 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Param20      	 4002259	       298 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParamWrite   	 7826979	       151 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubStatic 	11584101	       103 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubParam  	 7606005	       158 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GithubAll    	   36332	     34051 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusStatic  	12782667	        79.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusParam   	12041554	       103 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlus2Params 	 9379024	       128 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_GPlusAll     	  813216	      1394 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseStatic  	15016789	        77.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseParam   	15004710	        82.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_Parse2Params 	11183847	       109 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_ParseAll     	  448926	      2553 ns/op	       0 B/op	       0 allocs/op
BenchmarkGin_StaticAll    	   51507	     23745 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/julienschmidt/go-http-routing-benchmark	22.477s

ref issue: #1817 and #1644

cc @thinkerou @dmarkham @QianChenglong

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@codecov
Copy link

codecov bot commented Nov 28, 2019

Codecov Report

Merging #2159 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2159      +/-   ##
==========================================
+ Coverage   98.61%   98.61%   +<.01%     
==========================================
  Files          40       40              
  Lines        2238     2240       +2     
==========================================
+ Hits         2207     2209       +2     
  Misses         16       16              
  Partials       15       15
Impacted Files Coverage Δ
gin.go 98.29% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 231ff00...0b58c63. Read the comment docs.

Copy link
Member

@thinkerou thinkerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@appleboy appleboy merged commit 352d69c into gin-gonic:master Nov 28, 2019
@appleboy appleboy deleted the patch-3 branch November 28, 2019 16:02
ThomasObenaus pushed a commit to ThomasObenaus/gin that referenced this pull request Feb 19, 2020
…-gonic#2159)

* chore: Add RemoveExtraSlash flag

* fix testing

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
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.

2 participants