nothing special here

This commit is contained in:
Gerasimos Maropoulos 2016-09-18 21:57:15 +03:00
parent 2cb0d9981d
commit d00bd8e595
2 changed files with 17 additions and 16 deletions

10
http.go
View File

@ -1335,8 +1335,9 @@ type (
} }
serveMux struct { serveMux struct {
tree *muxTree tree *muxTree
lookups []*route lookups []*route
maxParameters uint8
onLookup func(Route) onLookup func(Route)
@ -1454,6 +1455,7 @@ func (mux *serveMux) build() (func(reqCtx *fasthttp.RequestCtx) string, func([]b
if tree == nil { if tree == nil {
//first time we register a route to this method with this domain //first time we register a route to this method with this domain
tree = &muxTree{method: r.method, subdomain: r.subdomain, entry: &muxEntry{}, next: nil} tree = &muxTree{method: r.method, subdomain: r.subdomain, entry: &muxEntry{}, next: nil}
if mux.tree == nil { if mux.tree == nil {
// it's the first entry // it's the first entry
mux.tree = tree mux.tree = tree
@ -1474,6 +1476,10 @@ func (mux *serveMux) build() (func(reqCtx *fasthttp.RequestCtx) string, func([]b
if err := tree.entry.add(r.path, r.middleware); err != nil { if err := tree.entry.add(r.path, r.middleware); err != nil {
mux.logger.Panic(err.Error()) mux.logger.Panic(err.Error())
} }
if mp := tree.entry.paramsLen; mp > mux.maxParameters {
mux.maxParameters = mp
}
} }
// optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :) // optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :)

23
iris.go
View File

@ -238,11 +238,11 @@ func New(setters ...OptionSetter) *Framework {
// set the servemux, which will provide us the public API also, with its context pool // set the servemux, which will provide us the public API also, with its context pool
mux := newServeMux(s.Logger) mux := newServeMux(s.Logger)
mux.onLookup = s.Plugins.DoPreLookup mux.onLookup = s.Plugins.DoPreLookup
s.contextPool.New = func() interface{} {
return &Context{framework: s, Params: make(PathParameters, s.mux.maxParameters)}
}
// set the public router API (and party) // set the public router API (and party)
s.muxAPI = &muxAPI{mux: mux, relativePath: "/"} s.muxAPI = &muxAPI{mux: mux, relativePath: "/"}
s.contextPool.New = func() interface{} {
return &Context{framework: s}
}
s.Servers = &ServerList{mux: mux, servers: make([]*Server, 0)} s.Servers = &ServerList{mux: mux, servers: make([]*Server, 0)}
s.Available = make(chan bool) s.Available = make(chan bool)
} }
@ -282,6 +282,7 @@ func (s *Framework) initialize() {
// prepare the mux & the server // prepare the mux & the server
s.mux.setCorrectPath(!s.Config.DisablePathCorrection) s.mux.setCorrectPath(!s.Config.DisablePathCorrection)
s.mux.setEscapePath(!s.Config.DisablePathEscape) s.mux.setEscapePath(!s.Config.DisablePathEscape)
// set the debug profiling handlers if ProfilePath is setted // set the debug profiling handlers if ProfilePath is setted
if debugPath := s.Config.ProfilePath; debugPath != "" { if debugPath := s.Config.ProfilePath; debugPath != "" {
s.Handle(MethodGet, debugPath+"/*action", profileMiddleware(debugPath)...) s.Handle(MethodGet, debugPath+"/*action", profileMiddleware(debugPath)...)
@ -298,15 +299,15 @@ func (s *Framework) initialize() {
if s.Config.CheckForUpdatesSync { if s.Config.CheckForUpdatesSync {
s.CheckForUpdates(false) s.CheckForUpdates(false)
} else if s.Config.CheckForUpdates { } else if s.Config.CheckForUpdates {
go func() { s.CheckForUpdates(false) }() go s.CheckForUpdates(false)
} }
} }
// AcquireCtx gets an Iris' Context from pool // AcquireCtx gets an Iris' Context from pool
// see iris.Handler & ReleaseCtx, Go() // see iris.Handler & ReleaseCtx, Go()
func AcquireCtx(reqCtx *fasthttp.RequestCtx) { func AcquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
Default.AcquireCtx(reqCtx) return Default.AcquireCtx(reqCtx)
} }
// ReleaseCtx puts the Iris' Context back to the pool in order to be re-used // ReleaseCtx puts the Iris' Context back to the pool in order to be re-used
@ -347,15 +348,9 @@ func (s *Framework) Go() error {
serve := s.mux.BuildHandler() serve := s.mux.BuildHandler()
// build the fasthttp handler to bind it to the servers // build the fasthttp handler to bind it to the servers
defaultHandler := func(reqCtx *fasthttp.RequestCtx) { defaultHandler := func(reqCtx *fasthttp.RequestCtx) {
ctx := s.contextPool.Get().(*Context) // Changed to use the pool's New 09/07/2016, ~ -4k nanoseconds(9 bench tests) per requests (better performance) ctx := s.AcquireCtx(reqCtx)
ctx.RequestCtx = reqCtx
serve(ctx) serve(ctx)
s.ReleaseCtx(ctx)
ctx.Params = ctx.Params[0:0]
ctx.middleware = nil
ctx.session = nil
s.contextPool.Put(ctx)
} }
s.Handler = defaultHandler s.Handler = defaultHandler