| 1 | # FAQ |
| 2 | |
| 3 | ## Managing Binary Size |
| 4 | |
| 5 | This package adds about `900K` to any binary that depends on it. |
| 6 | |
| 7 | Prior to 2019-05-16, this package could add about `2MB` to the size of |
| 8 | your binaries. We have now trimmed that by 60%, and the package |
| 9 | contributes less than `1MB`. This compares favorably to other packages like |
| 10 | `json-iterator/go` `(1MB)`. |
| 11 | |
| 12 | Of that `900Kb`, about `200Kb` is from an *optional* auto-generated file: |
| 13 | `fast-path.generated.go` that includes static generated implementations |
| 14 | providing much faster encoding and decoding of slices and maps |
| 15 | containing built-in numeric, boolean, string and interface{} types. |
| 16 | |
| 17 | Furthermore, you can bypass including `fast-path.generated.go` in your binary, |
| 18 | by building (or running tests and benchmarks) with the tag: `codec.notfastpath`. |
| 19 | |
| 20 | go install -tags codec.notfastpath |
| 21 | go build -tags codec.notfastpath |
| 22 | go test -tags codec.notfastpath |
| 23 | |
| 24 | With the tag `codec.notfastpath`, we trim that size to about `700Kb`. |
| 25 | |
| 26 | Please be aware of the following: |
| 27 | |
| 28 | - At least in our representative microbenchmarks for json (for example), |
| 29 | passing `codec.notfastpath` tag causes a clear performance loss (about 10%). |
| 30 | *YMMV*. |
| 31 | - These values were got from building the test binary that gives > 90% code coverage, |
| 32 | and running `go tool nm` on it to see how much space these library symbols took. |
| 33 | We consider that your use will touch much less of the library and you can be sure |
| 34 | that it will add less than 1MB to your binary. |
| 35 | |
| 36 | ## Resolving Module Issues |
| 37 | |
| 38 | Prior to v1.1.5, `go-codec` unknowingly introduced some headaches for its |
| 39 | users while introducing module support. We tried to make |
| 40 | `github.com/ugorji/go/codec` a module. At that time, multi-repository |
| 41 | module support was weak, so we reverted and made `github.com/ugorji/go/` |
| 42 | the module. |
| 43 | |
| 44 | However, folks previously used go-codec in module mode |
| 45 | before it formally supported modules. Eventually, different established packages |
| 46 | had go.mod files contain various real and pseudo versions of go-codec |
| 47 | which causes `go` to barf with `ambiguous import` error. |
| 48 | |
| 49 | To resolve this, from v1.1.5 and up, we use a requirements cycle between |
| 50 | modules `github.com/ugorji/go/codec` and `github.com/ugorji/go/`, |
| 51 | tagging them with parallel consistent tags (`codec/vX.Y.Z and vX.Y.Z`) |
| 52 | to the same commit. |
| 53 | |
| 54 | Fixing `ambiguous import` failure is now as simple as running |
| 55 | |
| 56 | ``` |
| 57 | go get -u github.com/ugorji/go/codec@latest |
| 58 | ``` |
| 59 | |
| 60 | ### Removing requirements cycle in v1.2.8 |
| 61 | |
| 62 | Unfortunately, due to the requirements cycle noted above, we cannot create a |
| 63 | valid `go.sum` until after the git version tags have been created. This is why |
| 64 | a `go.sum` has not been distributed with these 2 modules above. |
| 65 | |
| 66 | To fix that, starting with codec `v1.2.8`, we will remove the requirements cycle. |
| 67 | `github.com/ugorji/go/` will require `github.com/ugorji/go/codec` |
| 68 | but not vice versa. It has been over 3 years since we released `v1.1.7` (in July 2019) |
| 69 | with the requirements cycle to accomodate folks with an older version of |
| 70 | the `github.com/ugorji/go` module. We believe most folks now depend |
| 71 | either directly on the newer `github.com/ugorji/go/codec` module, or |
| 72 | on a newer `github.com/ugorji/go` module. |
| 73 | |
| 74 | ## Running on GCCGO |
| 75 | |
| 76 | You can use [gccgo](https://gcc.gnu.org/onlinedocs/gccgo/) [1](https://golang.org/doc/install/gccgo) |
| 77 | to build your applications that depend on this library. |
| 78 | This is fully tested. |
| 79 | |
| 80 | There's a caveat for contributors to the library. |
| 81 | If you are contributing to the library, you will need to run `./build.sh -m` at some point. |
| 82 | This has a failure on gccgo. Consequently, contributors must use the `gc` compiler. |
| 83 |