]> Cypherpunks repositories - gostls13.git/commit
net/http: avoid deferred unlock in ServeMux.shouldRedirect
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Mon, 21 May 2018 19:57:53 +0000 (12:57 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 21 Jun 2018 12:53:33 +0000 (12:53 +0000)
commit1988b3ed0ed72995f566630558e5bb0531aeac60
treec095e1fa8d0f281d67786c6a680b1db2593f3b8e
parent85e38cccb4d113862f4fd2c3c4d97927cd84420c
net/http: avoid deferred unlock in ServeMux.shouldRedirect

CL 96575 introduced concurrency protection for
ServeMux.shouldRedirect with a read lock and deferred unlock.
However, the change produced a noticeable regression.
Instead add the suffix "RLocked" to the function name to
declare that we should hold the read lock as a pre-requisite
before calling it, hence avoiding the defer altogether.

Benchmarks:
name                  old time/op    new time/op    delta
ServeMux-8              63.3µs ± 0%    54.6µs ± 0%  -13.74%  (p=0.000 n=9+9)
ServeMux_SkipServe-8    41.4µs ± 2%    32.7µs ± 1%  -21.05%  (p=0.000 n=10+10)

name                  old alloc/op   new alloc/op   delta
ServeMux-8              17.3kB ± 0%    17.3kB ± 0%     ~     (all equal)
ServeMux_SkipServe-8     0.00B          0.00B          ~     (all equal)

name                  old allocs/op  new allocs/op  delta
ServeMux-8                 360 ± 0%       360 ± 0%     ~     (all equal)
ServeMux_SkipServe-8      0.00           0.00          ~     (all equal)

Updates #25383
Updates #25482

Change-Id: I2ffa4eafe165faa961ce23bd29b5653a89facbc2
Reviewed-on: https://go-review.googlesource.com/113996
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/http/server.go