Skip to content

perf(query): faster valToBytes for UidID and PasswordID#9720

Open
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/query-valtobytes
Open

perf(query): faster valToBytes for UidID and PasswordID#9720
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:perf/query-valtobytes

Conversation

@shaunpatterson
Copy link
Copy Markdown
Contributor

UidID: build "0x"+hex via strconv.AppendUint into a pre-sized buffer instead of fmt.Sprintf("%#x") (output verified byte-identical incl. uid=0 and max uint64; keeps a type-assert fallback). PasswordID: use stringJsonMarshal instead of fmt.Sprintf("%q") — faster and produces proper JSON string escaping.

BenchmarkValToBytes: Uid 52n→18n (-65%, 2→1 allocs); Password 126n→35n (-73%, 3→1 allocs).


Independent change; branched from 4b9b399d. Verified: package unit tests pass + Go benchmark (benchstat, p<0.01). Single-thread microbenchmarks; not yet run through the Docker integration suite.

UidID: build "0x"+hex via strconv.AppendUint into a pre-sized buffer instead of
fmt.Sprintf("%#x") (output verified byte-identical, including uid=0 and max
uint64); keeps a type-assert fallback. PasswordID: use stringJsonMarshal instead
of fmt.Sprintf("%q") -- faster and produces proper JSON string escaping.

BenchmarkValToBytes:
  Uid:      52n -> 18n (-65%),  2 allocs -> 1
  Password: 126n -> 35n (-73%), 3 allocs -> 1
@shaunpatterson shaunpatterson requested a review from a team as a code owner May 28, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant