Commit Graph

6 Commits

Author SHA1 Message Date
wencyu
deae7ec345 Performance tuning for plugin/file (#7658)
* plugin/file: improve performance of function tree.less(..)

PrevLabel always begins its iteration from the tail of domain name.
less(..) loop can improve its performance by calling PrevLabel starting
from the last processed label.

As the benchmark results showed, the performance is improved by about 15%.
$ go test -bench=Less -run=^$
goos: linux
goarch: amd64
pkg: github.com/coredns/coredns/plugin/file/tree
cpu: Intel(R) Xeon(R) Platinum 8336C CPU @ 2.30GHz
BenchmarkLess/base-16              99003             12105 ns/op
BenchmarkLess/optimized-16        114522             10590 ns/op
PASS
ok      github.com/coredns/coredns/plugin/file/tree     2.416s

Signed-off-by: yuwenchao <ywc689@163.com>

* plugin/file: performance enhancement for nameFromRight(..)

Similar to tree.less(..), performance of function nameFromRight
can boost by utilizing dns.PrevLabel more efficiently.

As benchmark tests shown, performance of this function with the
optimization is gained by double or triple.

* Benchmark test result for the original implementation:
BenchmarkNameFromRight/i0_origin-16     430719652                2.794 ns/op
BenchmarkNameFromRight/eq_origin_i1_shot-16             30933135                37.52 ns/op
BenchmarkNameFromRight/two_labels_i1-16                 29375857                40.71 ns/op
BenchmarkNameFromRight/two_labels_i2-16                 18556830                63.97 ns/op
BenchmarkNameFromRight/two_labels_i3_shot-16            14678812                84.73 ns/op
BenchmarkNameFromRight/ten_labels_i5-16                  8522132               133.0 ns/op
BenchmarkNameFromRight/ten_labels_i11_shot-16            3154410               378.2 ns/op
BenchmarkNameFromRight/not_subdomain_shot-16            35297224                33.59 ns/op
BenchmarkNameFromRightRandomized-16                     10638702               113.4 ns/op             0 B/op          0 allocs/op

* Benchmark test result with this optimization:
BenchmarkNameFromRight/i0_origin-16     425864671                2.808 ns/op
BenchmarkNameFromRight/eq_origin_i1_shot-16             60903428                19.53 ns/op
BenchmarkNameFromRight/two_labels_i1-16                 50209297                24.21 ns/op
BenchmarkNameFromRight/two_labels_i2-16                 42483711                27.88 ns/op
BenchmarkNameFromRight/two_labels_i3_shot-16            40898925                29.24 ns/op
BenchmarkNameFromRight/ten_labels_i5-16                 27916532                44.54 ns/op
BenchmarkNameFromRight/ten_labels_i11_shot-16           17540040                67.59 ns/op
BenchmarkNameFromRight/not_subdomain_shot-16            67180514                17.46 ns/op
BenchmarkNameFromRightRandomized-16                     32692081                38.21 ns/op            0 B/op          0 allocs/op

Signed-off-by: yuwenchao <yuwenchao@bytedance.com>

---------

Signed-off-by: yuwenchao <ywc689@163.com>
Signed-off-by: yuwenchao <yuwenchao@bytedance.com>
Co-authored-by: yuwenchao <yuwenchao@bytedance.com>
2025-11-06 13:12:49 -08:00
Ville Vesilehto
70fb03f711 fix(file): fix data race in tree Elem.Name (#7574)
Eagerly set name in newElem and make Name() read-only to avoid
racy lazy writes under concurrent lookups. Add tests for empty-name
comparisons and concurrent access to Less/Name(). In addition,
regression tests to CloudDNS plugin.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-28 19:49:47 -07:00
Ville Vesilehto
19a6ae4983 lint: enable intrange linter (#7331)
Enable intrange linter to enforce modern Go range syntax over
traditional for loops, by converting:

for i := 0; i < n; i++

to:

for i := range n

Adding type conversions where needed for compatibility
with existing uint64 parameters.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-05-28 17:50:55 -07:00
Ondřej Benkovský
c2dbb7141a add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
Miek Gieben
725becd134 Stop importing testing in the main binary (#2479)
* Stop importing testing in the main binary

Stop importing "testing" into the main binary:

* test/helpers.go imported it; remote that and change function signature
* update all tests that use this

Signed-off-by: Miek Gieben <miek@miek.nl>

* Drop import testing from metrics plugin

Signed-off-by: Miek Gieben <miek@miek.nl>

* more fiddling

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-01-19 11:23:13 +00:00
Miek Gieben
d8714e64e4 Remove the word middleware (#1067)
* Rename middleware to plugin

first pass; mostly used 'sed', few spots where I manually changed
text.

This still builds a coredns binary.

* fmt error

* Rename AddMiddleware to AddPlugin

* Readd AddMiddleware to remain backwards compat
2017-09-14 09:36:06 +01:00