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

refactor: change pointer to struct #47

Merged
merged 22 commits into from
Jun 15, 2020

Conversation

suzuki-shunsuke
Copy link
Owner

@suzuki-shunsuke suzuki-shunsuke commented Jun 15, 2020

BREAKING CHNAGE: change the signature of structs

  • Ensure the transport isn't changed

Migration

  • Route.Matcher: *Matcher -> Matcher
  • Route.Tester: *Tester -> Tester
  • Route.Response: *Response -> Response
  • Tester.Test: func(*testing.T, *http.Request, *Service, *Route) -> func(*testing.T, *http.Request, Service, Route)
  • &Transport -> Transport

Benchmark

Before

https://cloud.drone.io/suzuki-shunsuke/flute/188/1/5

Benchmark_isMatchService-48           	14590218	        81.6 ns/op	       0 B/op	       0 allocs/op
--
9 | Benchmark_isMatch/if_mathcer_is_nil,_the_request_matches_the_matcher-48         	339309528	         3.52 ns/op	       0 B/op	       0 allocs/op
10 | Benchmark_isMatch/path_doesn't_match-48                                         	139038411	         8.29 ns/op	       0 B/op	       0 allocs/op
11 | Benchmark_isMatch/method_doesn't_match-48                                       	107690738	        10.9 ns/op	       0 B/op	       0 allocs/op
12 | Benchmark_isMatch/body_string_doesn't_match-48                                  	 4060524	       285 ns/op	     512 B/op	       1 allocs/op
13 | Benchmark_isMatch/body_json_doesn't_match-48                                    	 1000000	      1131 ns/op	     865 B/op	       7 allocs/op
14 | Benchmark_isMatch/body_json_string_doesn't_match-48                             	  863486	      1491 ns/op	     905 B/op	       9 allocs/op
15 | Benchmark_isMatch/header_doesn't_match-48                                       	 2101183	       565 ns/op	      96 B/op	       4 allocs/op
16 | Benchmark_isMatch/header_isn't_equal-48                                         	 6447096	       185 ns/op	       0 B/op	       0 allocs/op
17 | Benchmark_isMatch/query_doesn't_match-48                                        	 1000000	      1148 ns/op	     512 B/op	       7 allocs/op
18 | Benchmark_isMatch/query_isn't_equal-48                                          	 1273093	       976 ns/op	     432 B/op	       4 allocs/op
19 | Benchmark_isMatch/match_function_doesn't_match-48                               	127509306	         9.47 ns/op	       0 B/op	       0 allocs/op
20 | Benchmark_isMatchPartOfQuery/query_value_doesn't_match-48                       	 1000000	      1110 ns/op	     512 B/op	       7 allocs/op
21 | Benchmark_isMatchPartOfQuery/query_isn't_found-48                               	 6947854	       171 ns/op	      48 B/op	       1 allocs/op
22 | Benchmark_isMatchPartOfQuery/query_matches-48                                   	 1020055	      1160 ns/op	     512 B/op	       7 allocs/op
23 | Benchmark_isMatchPartOfHeader/header_value_doesn't_match-48                     	 2085816	       569 ns/op	      96 B/op	       4 allocs/op
24 | Benchmark_isMatchPartOfHeader/header_isn't_found-48                             	23195233	        52.0 ns/op	       0 B/op	       0 allocs/op
25 | Benchmark_isMatchPartOfHeader/header_matches-48                                 	 1913611	       612 ns/op	      96 B/op	       4 allocs/op
26 | Benchmark_isMatchBodyString/request_body_is_nil-48                              	291755187	         4.13 ns/op	       0 B/op	       0 allocs/op
27 | Benchmark_isMatchBodyString/request_body_matches-48                             	 4568509	       291 ns/op	     512 B/op	       1 allocs/op
28 | Benchmark_isMatchBodyString/request_body_doesn't_match-48                       	 3803454	       285 ns/op	     512 B/op	       1 allocs/op
29 | Benchmark_isMatchBodyJSONString/request_body_is_nil-48                          	285607687	         4.12 ns/op	       0 B/op	       0 allocs/op
30 | Benchmark_isMatchBodyJSONString/request_body_json_matches-48                    	  909519	      1402 ns/op	     929 B/op	       9 allocs/op
31 | Benchmark_isMatchBodyJSONString/request_body_json_doesn't_match-48              	  859863	      1422 ns/op	     929 B/op	       9 allocs/op
32 | Benchmark_isMatchBodyJSON/request_body_is_nil-48                                	291765010	         4.11 ns/op	       0 B/op	       0 allocs/op
33 | Benchmark_isMatchBodyJSON/request_body_json_matches-48                          	 1000000	      1032 ns/op	     865 B/op	       7 allocs/op
34 | Benchmark_isMatchBodyJSON/request_body_json_doesn't_match-48                    	 1000000	      1094 ns/op	     865 B/op	       7 allocs/op
35 | Benchmark_createHTTPResponse/body_json_isn't_nil-48                             	  771142	      1608 ns/op	     467 B/op	      11 allocs/op
36 | Benchmark_createHTTPResponse/failed_to_marshal_json-48                          	  717844	      1804 ns/op	     544 B/op	       7 allocs/op
37 | Benchmark_createHTTPResponse/body_string_isn't_nil-48                           	 3136261	       377 ns/op	     193 B/op	       3 allocs/op
38 | Benchmark_createHTTPResponse/nil_request_body-48                                	 3440731	       351 ns/op	     193 B/op	       3 allocs/op
39 | Benchmark_createHTTPResponse/resp.Response-48                                   	 3296454	       383 ns/op	     192 B/op	       3 allocs/op
40 | BenchmarkTransport_RoundTrip-48                                                 	  711099	      1794 ns/op	    1254 B/op	      15 allocs/op

After

https://cloud.drone.io/suzuki-shunsuke/flute/196/1/5

Benchmark_isMatchService-48         	16077306	        75.4 ns/op	       0 B/op	       0 allocs/op | 4s
-- | --
9 | Benchmark_isMatch/path_doesn't_match-48         	46152350	        25.9 ns/op	       0 B/op	       0 allocs/op | 6s
10 | Benchmark_isMatch/method_doesn't_match-48       	35202667	        34.0 ns/op	       0 B/op	       0 allocs/op | 7s
11 | Benchmark_isMatch/body_string_doesn't_match-48  	 4100803	       306 ns/op	     512 B/op	       1 allocs/op | 8s
12 | Benchmark_isMatch/body_json_doesn't_match-48    	 1000000	      1098 ns/op	     865 B/op	       7 allocs/op | 9s
13 | Benchmark_isMatch/body_json_string_doesn't_match-48         	  822428	      1452 ns/op	     905 B/op	       9 allocs/op | 11s
14 | Benchmark_isMatch/header_doesn't_match-48                   	 1977729	       608 ns/op	      96 B/op	       4 allocs/op | 13s
15 | Benchmark_isMatch/header_isn't_equal-48                     	 4586121	       262 ns/op	       0 B/op	       0 allocs/op | 14s
16 | Benchmark_isMatch/query_doesn't_match-48                    	  945764	      1115 ns/op	     512 B/op	       7 allocs/op | 15s
17 | Benchmark_isMatch/query_isn't_equal-48                      	 1269537	       940 ns/op	     432 B/op	       4 allocs/op | 17s
18 | Benchmark_isMatch/match_function_doesn't_match-48           	14641996	        81.9 ns/op	       0 B/op	       0 allocs/op | 18s
19 | Benchmark_matchPartOfQuery/query_value_doesn't_match-48     	 1000000	      1004 ns/op	     512 B/op	       7 allocs/op | 19s
20 | Benchmark_matchPartOfQuery/query_isn't_found-48             	 8235597	       148 ns/op	      48 B/op	       1 allocs/op | 21s
21 | Benchmark_matchPartOfQuery/query_matches-48                 	 1000000	      1067 ns/op	     512 B/op	       7 allocs/op | 22s
22 | Benchmark_matchPartOfHeader/header_value_doesn't_match-48   	 2214632	       544 ns/op	      96 B/op	       4 allocs/op | 24s
23 | Benchmark_matchPartOfHeader/header_isn't_found-48           	21893889	        55.3 ns/op	       0 B/op	       0 allocs/op | 25s
24 | Benchmark_matchPartOfHeader/header_matches-48               	 2038860	       584 ns/op	      96 B/op	       4 allocs/op | 27s
25 | Benchmark_matchBodyString/request_body_is_nil-48            	83614329	        14.4 ns/op	       0 B/op	       0 allocs/op | 28s
26 | Benchmark_matchBodyString/request_body_matches-48           	 4412060	       275 ns/op	     512 B/op	       1 allocs/op | 29s
27 | Benchmark_matchBodyString/request_body_doesn't_match-48     	 4413315	       273 ns/op	     512 B/op	       1 allocs/op | 31s
28 | Benchmark_matchBodyJSONString/request_body_is_nil-48        	83645400	        14.3 ns/op	       0 B/op	       0 allocs/op | 32s
29 | Benchmark_matchBodyJSONString/request_body_json_matches-48  	  859090	      1339 ns/op	     929 B/op	       9 allocs/op | 33s
30 | Benchmark_matchBodyJSONString/request_body_json_doesn't_match-48         	  885817	      1386 ns/op	     929 B/op	       9 allocs/op | 35s
31 | Benchmark_matchBodyJSON/request_body_is_nil-48                           	83624607	        14.4 ns/op	       0 B/op	       0 allocs/op | 36s
32 | Benchmark_matchBodyJSON/request_body_json_matches-48                     	 1000000	      1030 ns/op	     865 B/op	       7 allocs/op | 37s
33 | Benchmark_matchBodyJSON/request_body_json_doesn't_match-48               	 1000000	      1030 ns/op	     865 B/op	       7 allocs/op | 38s
34 | Benchmark_createHTTPResponse/body_json_isn't_nil-48                      	  775274	      1564 ns/op	     467 B/op	      11 allocs/op | 39s
35 | Benchmark_createHTTPResponse/failed_to_marshal_json-48                   	  706454	      1704 ns/op	     544 B/op	       7 allocs/op | 40s
36 | Benchmark_createHTTPResponse/body_string_isn't_nil-48                    	 3339332	       359 ns/op	     193 B/op	       3 allocs/op | 42s
37 | Benchmark_createHTTPResponse/nil_request_body-48                         	 3556734	       341 ns/op	     193 B/op	       3 allocs/op | 43s
38 | Benchmark_createHTTPResponse/resp.Response-48                            	 3410667	       352 ns/op	     193 B/op	       3 allocs/op | 45s
39 | BenchmarkTransport_RoundTrip-48                                          	  788850	      1514 ns/op	    1062 B/op	      11 allocs/op

BREAKING CHNAGE: change the signature of structs
@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2020

Codecov Report

Merging #47 into master will decrease coverage by 7.31%.
The diff coverage is 86.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
- Coverage   85.13%   77.81%   -7.32%     
==========================================
  Files           4        4              
  Lines         296      266      -30     
==========================================
- Hits          252      207      -45     
- Misses         32       44      +12     
- Partials       12       15       +3     
Impacted Files Coverage Δ
flute/tester.go 60.97% <78.68%> (-15.12%) ⬇️
flute/matcher.go 91.04% <100.00%> (-1.64%) ⬇️
flute/response.go 100.00% <100.00%> (ø)
flute/transport.go 91.07% <100.00%> (ø)

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 baf7f86...41f2dc0. Read the comment docs.

@suzuki-shunsuke suzuki-shunsuke merged commit 85e6bf6 into master Jun 15, 2020
@suzuki-shunsuke suzuki-shunsuke changed the title perf: change pointer to struct refactor: change pointer to struct Jun 15, 2020
@suzuki-shunsuke suzuki-shunsuke deleted the refactor/change-pointer-to-struct branch June 15, 2020 07:08
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