cockroachdb / errors

Go error library with error portability over the network
Apache License 2.0
2.07k stars 66 forks source link

Package has dependency of GoGO protobufs and too mainy inits #80

Open linux019 opened 3 years ago

linux019 commented 3 years ago

When inspecting go binary I found that it requires gogo protobufs https://github.com/cockroachdb/errors/blob/72ec75208141a2b67e79909b28aea29ed2189108/extgrpc/ext_grpc.go#L182 in init() I do not use gogo in production as it is an outdated project https://github.com/gogo/protobuf/issues/691 Please remove init and gogo dependency

knz commented 3 years ago

I don't understand your request.

The "extgrpc" sub-package is merely an example:

  1. it's not required by the errors base package. Why do you think it is a dependency?
  2. to achieve what it does (error transport across RPCs), the simplest implementation is the one provided, using gogoproto. You are free to implement your own variant of this example which does not use gogoproto.
linux019 commented 3 years ago

go build -o main1 main.go I used this tool https://github.com/jondot/goweight to analyze binary

  1. compiled binary has size 8MB. As you can see from output the binary contains gogo libs that are not used
package main

import (
    "log"
    "strconv"

    "github.com/cockroachdb/errors"
)

func main() {
    log.Println(f())
}

func f() error {
    _, err := strconv.Atoi("1122")
    return errors.Wrap(err, "ttt")
}

 ~/go/bin/goweight .|head -n 10
  7.3 MB runtime
  6.3 MB net/http
  4.3 MB github.com/gogo/protobuf/proto
  3.4 MB github.com/gogo/protobuf/types
  2.9 MB net
  2.7 MB crypto/tls
  2.4 MB reflect
  1.7 MB github.com/gogo/protobuf/protoc-gen-gogo/descriptor
  1.6 MB math/big
  1.5 MB syscall
  1. Same program, but it uses another errors lib and size of compiled binary it's only 2MB :)
    
    package main

import ( "log" "strconv"

"github.com/pkg/errors"

)

func main() { log.Println(f()) }

func f() error { _, err := strconv.Atoi("1122") return errors.Wrap(err, "ttt") }

~/go/bin/goweight .|head -n 10 7.3 MB runtime 2.4 MB reflect 1.5 MB syscall 873 kB time 777 kB os 710 kB internal/reflectlite 694 kB fmt 476 kB strconv 460 kB internal/poll 446 kB strings

knz commented 3 years ago

Ok so the problem is not with the extgrpc package specifically.

We'll look into it

StevenACoffman commented 2 years ago

Yeah, I think this is maybe why I cannot use cockroachdb/errors in the Go playground.

1379 commented 1 year ago

Is there any new progress in this problem? I saw that this library has not been updated for a long time, so I want to ask, is this library still maintained?

knz commented 1 year ago

Yes this is still actively maintained.

1379 commented 1 year ago

Is there any new progress in this problem?After using this library, my program volume has increased a lot

StevenACoffman commented 1 year ago

@1379 This errors package is amazing, but since it has so many features, it makes it very heavy weight. That's just the tradeoff.

However, if you just want to use errors with StackTraces (and don't need protobuf, network portability, PII redaction, etc.) you can just use something like https://github.com/StevenACoffman/simplerr that also reconciles the pkg/errors with std lib errors, but with out the other goodies.

1379 commented 1 year ago

Thanks!

linux019 commented 1 year ago

GoGo protobufs is a dead project. The dependency on gogo can be removed without any subsequent issues