Skip to content

graph-guard/gqlscan

Repository files navigation

GraphQL Logo (Rhodamine) 4 (1)

GitHub Actions: CI Coverage Status GoReportCard GoDoc

gqlscan provides functions for fast and allocation-free lexical scanning and validation of GraphQL queries according to the GraphQL specification of October 2021.

The provided functions don't perform semantic analysis such as making sure that declared variables are used or that values match their declared types, etc. as this is outside the scope of lexical analysis.

Benchmark

All tests were performed on an Apple M1 Max 14" MBP running macOS Monterey 12.4.

Benchmark Suite

The benchmark suite allows testing arbitrary query sets for throughput.

go run cmd/bench/main.go -i cmd/bench/inputs

Single core:

gathered 4 input file(s):
 inputs/complex.graphql: 2.2 kB
 inputs/longstr.graphql: 3.8 kB
 inputs/longstr_blk.graphql: 4.4 kB
 inputs/small.graphql: 28 B
running 1 parallel goroutine(s) for 1m0s
finished (1m0.000025417s)
total processed: 72 GB (1.2 GB/s; 8.96 gbit/s)
total errors: 0

Multicore:

gathered 4 input file(s):
 inputs/complex.graphql: 2.2 kB
 inputs/longstr.graphql: 3.8 kB
 inputs/longstr_blk.graphql: 4.4 kB
 inputs/small.graphql: 28 B
running 10 parallel goroutine(s) for 1m0s
finished (1m0.000055208s)
total processed: 593 GB (9.9 GB/s; 73.66 gbit/s)
total errors: 0

Test Benchmarks

Тhe test benchmarks benchmark all test inputs.

go test -v -bench . -benchmem ./...
goos: darwin
goarch: arm64
pkg: github.com/graph-guard/gqlscan
BenchmarkScanAll
BenchmarkScanAll/gqlscan_test.go:29
BenchmarkScanAll/gqlscan_test.go:29-10         	370445240	        32.39 ns/op	       0 B/op	       0 allocs/op
BenchmarkScanAll/gqlscan_test.go:263
BenchmarkScanAll/gqlscan_test.go:263-10        	 5368155	      2236 ns/o       0 B/op	       0 allocs/op
PASS
ok  	github.com/graph-guard/gqlscan	29.850s