Skip to content

Commit

Permalink
Pre-compile routes at Serve() time
Browse files Browse the repository at this point in the history
I originally exposed Compile() for exactly this use case, but apparently
I never actually implemented this. Oops.

In any event, this makes the first request a little faster (an extremely
unscientific test suggests on the order of 10 microseconds). Also, if
something goes terribly wrong during route compilation, it would fail
before we start listening on the socket.
  • Loading branch information
zenazn committed Oct 27, 2014
1 parent 89bc831 commit a655411
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Serve() {
flag.Parse()
}

DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux.
// This allows packages like expvar to continue working as expected.
http.Handle("/", DefaultMux)
Expand Down
1 change: 1 addition & 0 deletions serve_appengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "net/http"

// Serve starts Goji using reasonable defaults.
func Serve() {
DefaultMux.Compile()
// Install our handler at the root of the standard net/http default mux.
// This is required for App Engine, and also allows packages like expvar
// to continue working as expected.
Expand Down

0 comments on commit a655411

Please sign in to comment.