sharded-gotify/api
Eng Zer Jun 0bfa5ca4d9
perf: avoid allocations with `(*regexp.Regexp).MatchString` (#604)
We should use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` when matching string to avoid
unnecessary `[]byte` conversions and reduce allocations.

Example benchmark:

var allowedOrigin = regexp.MustCompile(".*.example.com")

func BenchmarkMatch(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := allowedOrigin.Match([]byte("www.example.com")); !match {
			b.Fail()
		}
	}
}

func BenchmarkMatchString(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if match := allowedOrigin.MatchString("wwww.example.com"); !match {
			b.Fail()
		}
	}
}

goos: linux
goarch: amd64
pkg: github.com/gotify/server/v2/api/stream
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16          	 2076819	       647.7 ns/op	      16 B/op	       1 allocs/op
BenchmarkMatchString-16    	 2536326	       442.0 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/gotify/server/v2/api/stream	3.552s

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-10-23 15:57:15 +00:00
..
stream perf: avoid allocations with `(*regexp.Regexp).MatchString` (#604) 2023-10-23 15:57:15 +00:00
application.go fix: update go-swagger 2023-09-16 21:06:54 +02:00
application_test.go Add last used to client & application 2023-08-06 12:30:22 +02:00
client.go fix: update go-swagger 2023-09-16 21:06:54 +02:00
client_test.go Add last used to client & application 2023-08-06 12:30:22 +02:00
errorHandling.go Return 500 server error on database failures (#191) 2019-05-25 08:37:24 +02:00
errorHandling_test.go Return 500 server error on database failures (#191) 2019-05-25 08:37:24 +02:00
health.go fix: update go-swagger 2023-09-16 21:06:54 +02:00
health_test.go Use v2 in package path 2020-05-08 10:43:17 +02:00
internalutil.go Allow delete for > uint32 ids 2020-07-01 19:44:06 +02:00
message.go fix: update go-swagger 2023-09-16 21:06:54 +02:00
message_test.go Add default message priority for applications 2023-07-19 18:15:01 +00:00
plugin.go fix: update go-swagger 2023-09-16 21:06:54 +02:00
plugin_test.go Use golangci-lint 2020-11-01 10:47:02 +01:00
tokens.go Use v2 in package path 2020-05-08 10:43:17 +02:00
tokens_test.go Use crypto/rand for token generation (#161) 2019-03-16 11:10:28 +01:00
user.go fix: remove unused code 2023-09-16 21:06:54 +02:00
user_test.go Add registration 2021-08-04 19:39:43 +02:00