Skip to content

Conversation

Skyenought
Copy link
Contributor

@Skyenought Skyenought commented May 26, 2023

What type of PR is this?

chore

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>.
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo.

(Optional) Translate the PR title into Chinese.

去除 tree 中 find AnyParam 节点中无意义的代码

@Skyenought Skyenought requested review from a team as code owners May 26, 2023 05:00
@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.68%. Comparing base (e8af33f) to head (70a8f78).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #793   +/-   ##
========================================
  Coverage    73.68%   73.68%           
========================================
  Files          145      145           
  Lines        16860    16860           
========================================
  Hits         12423    12423           
  Misses        3848     3848           
  Partials       589      589           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@li-jin-gou
Copy link
Member

thanks

@Skyenought
Copy link
Contributor Author

zh: 修改后, 寻找 any 节点的速度比之前快了一倍

BenchMark code

func BenchmarkFindAnyParam(b *testing.B) {
	var isNil bool
	tree := &router{method: "GET", root: &node{}}
	routes := [...]string{
		"/hi/hello/test/*any",
		"/b",
		"/ABC",
		"/search/*query",
		"/src/*filepath",
		"/x",
		"/x/y",
		"/y/z",
		"/1/:id/2",
		"/aa",
		"/a/*any",
		"/doc",
		"/doc/go1.html",
		"/doc/go/away",
		"/no/a",
		"/no/b",
		"/z/:age",
		"/x/3/4",
		"/x/:age/5",
	}
	
	for _, route := range routes {
		recv := catchPanic(func() {
			tree.addRoute(route, fakeHandler(route))
		})
		if recv != nil {
			b.Fatalf("panic inserting route '%s': %v", route, recv)
		}
	}
	v := make(param.Params, 0, 10)
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		value := tree.find("/hi/hello/test/sth", &v, false)
		if value.handlers == nil {
			isNil = true
		} else {
			isNil = false
		}
	}
	b.StopTimer()
	assert.DeepEqual(b, isNil, false)
}

before:

goos: linux
goarch: amd64
pkg: github.com/cloudwego/hertz/pkg/route
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkFindAnyParam
BenchmarkFindAnyParam-2         26044662                49.24 ns/op
PASS

after change:

goos: linux
goarch: amd64
pkg: github.com/cloudwego/hertz/pkg/route
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkFindAnyParam
BenchmarkFindAnyParam-2         49172884                23.27 ns/op
PASS

@welkeyever

@Skyenought Skyenought requested a review from Duslia September 19, 2023 10:04
@xiaost xiaost changed the title optimize: remove useless code from tree chore(router): remove useless code from tree May 27, 2025
@xiaost xiaost changed the title chore(router): remove useless code from tree chore(route): remove useless code from tree May 27, 2025
@xiaost xiaost merged commit 5513927 into cloudwego:develop May 27, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants