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

perf: skip debug work when not in debug mode #60

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: skip debug work when not in debug mode
MergedFileDescriptors was unconditionally checking import paths and file
descriptor differences, then conditionally returning the differences as
an error. There is no need to check the differences if we will never
return them.

This made a measurable difference in running simd q:

$ hyperfine --warmup 4 -r 50 '/tmp/simd-dodebugwork q' '/tmp/simd-skipdebugwork q'
Benchmark 1: /tmp/simd-dodebugwork q
  Time (mean ± σ):     121.6 ms ±   6.5 ms    [User: 173.6 ms, System: 23.7 ms]
  Range (min … max):   117.0 ms … 162.7 ms    50 runs

  Warning: Statistical outliers were detected. ...

Benchmark 2: /tmp/simd-skipdebugwork q
  Time (mean ± σ):     113.6 ms ±   6.5 ms    [User: 158.5 ms, System: 23.1 ms]
  Range (min … max):   109.3 ms … 139.7 ms    50 runs

  Warning: Statistical outliers were detected. ...

Summary
  '/tmp/simd-skipdebugwork q' ran
    1.07 ± 0.08 times faster than '/tmp/simd-dodebugwork q'

And on two single runs of TestAppStateDeterminism, this optimization
reduced local runtime from 20.9 seconds to 19.7, an anecdotal ~6%
speedup.
  • Loading branch information
mark-rushakoff committed Apr 13, 2023
commit 5db04f038017eb8033cf853de91d80f76a9c11d2
19 changes: 12 additions & 7 deletions proto/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ func mergedFileDescriptors(debug bool) (*descriptorpb.FileDescriptorSet, error)
}

// While combing through the file descriptors, we'll also log any errors
// we encounter.
// we encounter -- only if debug is true. Otherwise, we will skip the work
// to check import path or file descriptor differences.
var (
checkImportErr []string
diffErr []string
)

// Add protoregistry file descriptors to our final file descriptor set.
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
fd := protodesc.ToFileDescriptorProto(fileDescriptor)
if err := CheckImportPath(fd.GetName(), fd.GetPackage()); err != nil {
checkImportErr = append(checkImportErr, err.Error())
if debug {
fd := protodesc.ToFileDescriptorProto(fileDescriptor)
if err := CheckImportPath(fd.GetName(), fd.GetPackage()); err != nil {
checkImportErr = append(checkImportErr, err.Error())
}
}

fds.File = append(fds.File, protodesc.ToFileDescriptorProto(fileDescriptor))
Expand Down Expand Up @@ -92,9 +95,11 @@ func mergedFileDescriptors(debug bool) (*descriptorpb.FileDescriptorSet, error)
return nil, err
}

err := CheckImportPath(fd.GetName(), fd.GetPackage())
if err != nil {
checkImportErr = append(checkImportErr, err.Error())
if debug {
err := CheckImportPath(fd.GetName(), fd.GetPackage())
if err != nil {
checkImportErr = append(checkImportErr, err.Error())
}
}

// If it's not in the protoregistry file descriptors, add it.
Expand Down