Skip to content

Conversation

@benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Aug 20, 2025

DRAFT: not yet ready for review. And I still need to figure out how this applies to snapd and run it past them.

Oddly, it doesn't decrease the binary size. In fact, building with the flags we use to build the snap, it's very slightly bigger (exactly 4096 = 4KB). Not sure why, maybe something's bumped it into using another 4KB "page".

In terms of performance, routing is 30% faster, and does fewer memory allocations. Not that that is a big driver here, both are at the millisecond level. But here are the numbers of this benchmark:

          │ router_gorilla.txt │         router_servemux.txt         │
          │       sec/op       │   sec/op     vs base                │
Router-16          2.699µ ± 6%   1.850µ ± 7%  -31.44% (p=0.000 n=10)

          │ router_gorilla.txt │         router_servemux.txt          │
          │        B/op        │     B/op      vs base                │
Router-16         3.406Ki ± 0%   2.574Ki ± 0%  -24.43% (p=0.000 n=10)

          │ router_gorilla.txt │        router_servemux.txt         │
          │     allocs/op      │ allocs/op   vs base                │
Router-16           31.00 ± 0%   24.00 ± 0%  -22.58% (p=0.000 n=10)

Fixes #676.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors Pebble's HTTP routing from gorilla/mux to Go 1.22's native ServeMux path patterns to improve performance and reduce dependencies.

  • Replaced gorilla/mux with http.ServeMux for HTTP routing
  • Updated path parameter extraction from muxVars(req)["param"] to req.PathValue("param")
  • Simplified path patterns to match ServeMux syntax (e.g., {task-id} to {taskID})

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internals/daemon/daemon.go Replace mux.Router with http.ServeMux and simplify route registration
internals/daemon/api.go Remove mux dependency and update path patterns to use camelCase
internals/daemon/api_changes.go Update parameter extraction to use req.PathValue()
internals/daemon/api_notices.go Update parameter extraction to use req.PathValue()
internals/daemon/api_tasks.go Update parameter extraction to use req.PathValue()
internals/daemon/daemon_test.go Refactor tests to use HTTP requests instead of mux internals
internals/daemon/export_test.go Remove mux-related test utilities
internals/daemon/api_test.go Remove mux test setup and helper functions
internals/daemon/api_changes_test.go Update tests to use req.SetPathValue()
internals/daemon/api_notices_test.go Update tests to use req.SetPathValue()
go.mod Remove gorilla/mux dependency
docs/specs/openapi.yaml Update API documentation to reflect new path patterns
docs/explanation/api-and-clients.md Update documentation examples
HACKING.md Remove mux import from example code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +489 to 494
d.router = http.NewServeMux()

for _, c := range API {
c.d = d
if c.PathPrefix == "" {
d.router.Handle(c.Path, c).Name(c.Path)
} else {
d.router.PathPrefix(c.PathPrefix).Handler(c).Name(c.PathPrefix)
}
d.router.Handle(c.Path, c)
}
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of NotFoundHandler registration means requests to invalid endpoints will now receive Go's default 404 response instead of the custom NotFound() response. This changes the API behavior and error format returned to clients.

Copilot uses AI. Check for mistakes.
Path string
PathPrefix string
//
Path string
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PathPrefix field has been removed from the Command struct, but there's no clear indication of how prefix-based routing is now handled. If any commands previously used PathPrefix, this could be a breaking change.

Suggested change
Path string
Path string
PathPrefix string

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace gorilla/mux with http.ServeMux path patterns

1 participant