Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perfomance json decoding using go-json #3405

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lkeix
Copy link
Contributor

@lkeix lkeix 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
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