Skip to content

Improve perfomance json decoding using go-json#3405

Open
n9te9 wants to merge 5 commits into
99designs:masterfrom
n9te9:master
Open

Improve perfomance json decoding using go-json#3405
n9te9 wants to merge 5 commits into
99designs:masterfrom
n9te9:master

Conversation

@n9te9
Copy link
Copy Markdown
Contributor

@n9te9 n9te9 commented Dec 4, 2024

Description

See related:

This PR optimizes JSON decoding. Specifically:
These changes aim to improve the performance of the gqlgen server, especially in high-throughput scenarios.

Related Issue
Resolves #3372 (replace with actual issue link)

Benchmark

I took benchmark simple code.
schema is generated project initialization.

resolver implementation

// CreateTodo is the resolver for the createTodo field.
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
	return &model.Todo{}, nil
}

// Todos is the resolver for the todos field.
func (r *queryResolver) Todos(ctx context.Context) ([]*model.Todo, error) {
	return []*model.Todo{}, nil
}

// Messages is the resolver for the messages field.
func (r *subscriptionResolver) Messages(ctx context.Context) (<-chan *model.Message, error) {
	return make(chan *model.Message), nil
}

// Mutation returns MutationResolver implementation.
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }

// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

// Subscription returns SubscriptionResolver implementation.
func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} }

go test bench overview is below.

# encoding/json
$ go test -bench . -benchmem -cpuprofile=cpu.prof -memprofile=mem.prof
goos: darwin
goarch: amd64
pkg: github.com/99designs/gqlgen/cmd/benchmark_tests
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkPost-16       	    3578	    316744 ns/op	   21447 B/op	     155 allocs/op
BenchmarkGet-16        	    2896	    383965 ns/op	   21101 B/op	     161 allocs/op
BenchmarkWebsock-16    	    2947	    397610 ns/op	   20414 B/op	     159 allocs/op
# goccy/go-json
$ go test -bench . -benchmem -cpuprofile=cpu-improve.prof -memprofile=mem-improve.prof
goos: darwin
goarch: amd64
pkg: github.com/99designs/gqlgen/cmd/benchmark_tests
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkPost-16       	    4328	    262948 ns/op	   20910 B/op	     155 allocs/op
BenchmarkGet-16        	    3211	    354725 ns/op	   20547 B/op	     157 allocs/op
BenchmarkWebsock-16    	    3070	    368349 ns/op	   20286 B/op	     156 allocs/op

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@StevenACoffman StevenACoffman changed the title Imrpove perfomance json decoding using go-json Improve perfomance json decoding using go-json Dec 4, 2024
@StevenACoffman StevenACoffman self-requested a review as a code owner March 17, 2026 11:19
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.

Improve: optimize graphql runtime

1 participant