| 1 |
name: Go |
| 2 |
# A change of the documents alone ( the paths-ignore below, the same for both events ) runs nothing: they affect no build, test or benchmark. |
| 3 |
# A push or a pull request which changes any other file runs everything. |
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: |
| 7 |
- master |
| 8 |
paths-ignore: |
| 9 |
- '**.md' |
| 10 |
- 'LICENSE' |
| 11 |
- 'benchmarks/licenses/**' |
| 12 |
- '.github/FUNDING.yml' |
| 13 |
pull_request: |
| 14 |
paths-ignore: |
| 15 |
- '**.md' |
| 16 |
- 'LICENSE' |
| 17 |
- 'benchmarks/licenses/**' |
| 18 |
- '.github/FUNDING.yml' |
| 19 |
jobs: |
| 20 |
build: |
| 21 |
name: Build on limited environment |
| 22 |
runs-on: ubuntu-latest |
| 23 |
steps: |
| 24 |
- name: checkout |
| 25 |
uses: actions/checkout@v7 |
| 26 |
- name: build |
| 27 |
run: docker compose run go-json |
| 28 |
|
| 29 |
test: |
| 30 |
name: Test |
| 31 |
strategy: |
| 32 |
fail-fast: false |
| 33 |
matrix: |
| 34 |
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ] |
| 35 |
go-version: [ "1.25", "1.26", "1.27" ] |
| 36 |
runs-on: ${{ matrix.os }} |
| 37 |
steps: |
| 38 |
- name: checkout |
| 39 |
uses: actions/checkout@v7 |
| 40 |
- name: setup Go ${{ matrix.go-version }} |
| 41 |
uses: actions/setup-go@v7 |
| 42 |
with: |
| 43 |
go-version: ${{ matrix.go-version }} |
| 44 |
- name: simple test |
| 45 |
run: go test -v ./... -count=1 |
| 46 |
- name: test with GC pressure |
| 47 |
run: go test -v ./... -count=1 |
| 48 |
env: |
| 49 |
GOGC: 1 |
| 50 |
- name: test with race detector |
| 51 |
run: go test -v -race ./... -count=1 |
| 52 |
|
| 53 |
test-big-endian: |
| 54 |
# The code which reads several bytes at once as a word must find them in the order of memory on a big-endian |
| 55 |
# machine too: the tests run on linux/s390x, whose binaries QEMU runs, since no runner is big-endian. |
| 56 |
name: Test on a big-endian machine (s390x) |
| 57 |
runs-on: ubuntu-latest |
| 58 |
steps: |
| 59 |
- name: checkout |
| 60 |
uses: actions/checkout@v7 |
| 61 |
- name: setup Go |
| 62 |
uses: actions/setup-go@v7 |
| 63 |
with: |
| 64 |
go-version: '1.27' |
| 65 |
- name: setup QEMU |
| 66 |
uses: docker/setup-qemu-action@v4 |
| 67 |
with: |
| 68 |
platforms: s390x |
| 69 |
- name: test |
| 70 |
run: go test -v ./... -count=1 |
| 71 |
env: |
| 72 |
GOARCH: s390x |
| 73 |
|
| 74 |
lint: |
| 75 |
name: Lint |
| 76 |
runs-on: ubuntu-latest |
| 77 |
steps: |
| 78 |
- name: checkout |
| 79 |
uses: actions/checkout@v7 |
| 80 |
- name: setup Go |
| 81 |
uses: actions/setup-go@v7 |
| 82 |
with: |
| 83 |
go-version: '1.27' |
| 84 |
- name: lint |
| 85 |
run: | |
| 86 |
make lint |
| 87 |
bench: |
| 88 |
# The benchmarks are measured by parts, one by each job, so that the check ends within a few minutes. |
| 89 |
# The decode and the encode benchmarks are apart, so that each group is judged by a mean of its own: |
| 90 |
# in a mean of both, a change of the decoder would count for less than one of the encoder, whose |
| 91 |
# benchmarks are more. The decode ones are in three parts and the encode ones in two, each with benchmarks of |
| 92 |
# every kind ( see -shard of internal/cmd/benchcheck ). |
| 93 |
name: Benchmark (${{ matrix.part }}) |
| 94 |
runs-on: ubuntu-latest |
| 95 |
strategy: |
| 96 |
fail-fast: false |
| 97 |
matrix: |
| 98 |
include: |
| 99 |
- part: decode 0/3 |
| 100 |
flags: -group decode -shard 0/3 |
| 101 |
- part: decode 1/3 |
| 102 |
flags: -group decode -shard 1/3 |
| 103 |
- part: decode 2/3 |
| 104 |
flags: -group decode -shard 2/3 |
| 105 |
- part: encode 0/2 |
| 106 |
flags: -group encode -shard 0/2 |
| 107 |
- part: encode 1/2 |
| 108 |
flags: -group encode -shard 1/2 |
| 109 |
steps: |
| 110 |
- name: checkout |
| 111 |
uses: actions/checkout@v7 |
| 112 |
with: |
| 113 |
# the master branch is required to measure the baseline. |
| 114 |
fetch-depth: 0 |
| 115 |
- name: setup Go |
| 116 |
uses: actions/setup-go@v7 |
| 117 |
with: |
| 118 |
go-version: '1.27' |
| 119 |
cache-dependency-path: | |
| 120 |
go.sum |
| 121 |
benchmarks/go.sum |
| 122 |
# A verdict is saved only when the job succeeds, so a failed commit is measured again. |
| 123 |
# The key has the attempt of the run: re-running the job measures again, on the machine it gets, |
| 124 |
# because the machines of the CI differ and a single measurement is not conclusive. |
| 125 |
# The baseline is always measured in the same job because it is never shared between machines. |
| 126 |
- name: restore benchmark verdict |
| 127 |
uses: actions/cache@v6 |
| 128 |
with: |
| 129 |
path: .git/benchcheck/verdict |
| 130 |
key: benchcheck-verdict-${{ github.sha }}-${{ github.run_attempt }}-${{ matrix.part }} |
| 131 |
- name: check performance degradation |
| 132 |
run: make bench-check BENCH_CHECK_FLAGS="-base origin/master ${{ matrix.flags }}" |
| 133 |
|
| 134 |
bench-last-commit: |
| 135 |
# It never fails by the result: it measures what the last commit of a pull request changed, by parts. |
| 136 |
if: github.event_name == 'pull_request' |
| 137 |
name: Measure the last commit (${{ matrix.part }}) |
| 138 |
runs-on: ubuntu-latest |
| 139 |
strategy: |
| 140 |
fail-fast: false |
| 141 |
matrix: |
| 142 |
include: |
| 143 |
- part: decode 0/3 |
| 144 |
flags: -group decode -shard 0/3 |
| 145 |
- part: decode 1/3 |
| 146 |
flags: -group decode -shard 1/3 |
| 147 |
- part: decode 2/3 |
| 148 |
flags: -group decode -shard 2/3 |
| 149 |
- part: encode 0/2 |
| 150 |
flags: -group encode -shard 0/2 |
| 151 |
- part: encode 1/2 |
| 152 |
flags: -group encode -shard 1/2 |
| 153 |
steps: |
| 154 |
- name: checkout |
| 155 |
uses: actions/checkout@v7 |
| 156 |
with: |
| 157 |
# the previous commit is required to measure what the last commit changed. |
| 158 |
fetch-depth: 0 |
| 159 |
- name: setup Go |
| 160 |
uses: actions/setup-go@v7 |
| 161 |
with: |
| 162 |
go-version: '1.27' |
| 163 |
cache-dependency-path: | |
| 164 |
go.sum |
| 165 |
benchmarks/go.sum |
| 166 |
# The machines of the CI differ, so a commit is compared with its parent on the same machine. |
| 167 |
# HEAD is the merge commit of the pull request, whose second parent is the head of the branch. |
| 168 |
- name: measure what the last commit changed |
| 169 |
run: make bench-check BENCH_CHECK_FLAGS="-base HEAD^2~1 -no-cache -bench 'Encode_|Marshal|Twitter|Decode|Unmarshal' ${{ matrix.flags }}" || true |
| 170 |
|
| 171 |
bench-compare: |
| 172 |
# It never fails by the result: it exists to read how go-json compares with sonic on amd64, |
| 173 |
# where sonic compiles the encoder of a type to machine code. Each task is a job of its own. |
| 174 |
name: Compare with sonic (${{ matrix.name }}) |
| 175 |
runs-on: ubuntu-latest |
| 176 |
strategy: |
| 177 |
fail-fast: false |
| 178 |
matrix: |
| 179 |
include: |
| 180 |
- name: encode |
| 181 |
run: make bench-compare-encode |
| 182 |
# sonic inlines the nested structs into the code of a type up to 3 levels by default. |
| 183 |
# It is also measured with more levels, so that it is compared in the way which is the best for it. |
| 184 |
- name: encode, sonic inlining more |
| 185 |
run: SONIC_MAX_INLINE_DEPTH=10 make bench-compare-encode |
| 186 |
- name: decode |
| 187 |
run: make bench-compare-decode && make bench-profile-decode |
| 188 |
# sonic has two decoders on amd64, which the environment chooses: the JIT one by default, and optdec. |
| 189 |
# It is measured with each, and with its faster decoding of maps, so that it is compared at its best. |
| 190 |
- name: decode, sonic optdec |
| 191 |
run: SONIC_USE_OPTDEC=1 make bench-compare-decode |
| 192 |
- name: decode, sonic fastmap |
| 193 |
run: SONIC_USE_FASTMAP=1 make bench-compare-decode |
| 194 |
# A program which decodes JSON has a live heap of its own, which sets the goal of the GC for every |
| 195 |
# library alike ( see benchmarks/live_heap_test.go ): it is measured with one too, as a real program runs. |
| 196 |
- name: decode, live heap |
| 197 |
run: BENCH_LIVE_HEAP_MB=64 make bench-compare-decode |
| 198 |
- name: decode, live heap, sonic optdec |
| 199 |
run: BENCH_LIVE_HEAP_MB=64 SONIC_USE_OPTDEC=1 make bench-compare-decode |
| 200 |
- name: profile encode |
| 201 |
run: make bench-profile-encode |
| 202 |
- name: candidates of the optimizations |
| 203 |
run: make bench-variants |
| 204 |
steps: |
| 205 |
- name: checkout |
| 206 |
uses: actions/checkout@v7 |
| 207 |
- name: setup Go |
| 208 |
uses: actions/setup-go@v7 |
| 209 |
with: |
| 210 |
go-version: '1.27' |
| 211 |
cache-dependency-path: | |
| 212 |
go.sum |
| 213 |
benchmarks/go.sum |
| 214 |
- name: ${{ matrix.name }} |
| 215 |
run: ${{ matrix.run }} |
| 216 |
|
| 217 |
coverage: |
| 218 |
name: Coverage |
| 219 |
runs-on: ubuntu-latest |
| 220 |
steps: |
| 221 |
- name: checkout |
| 222 |
uses: actions/checkout@v7 |
| 223 |
- name: setup Go |
| 224 |
uses: actions/setup-go@v7 |
| 225 |
with: |
| 226 |
go-version: '1.27' |
| 227 |
- name: measure coverage |
| 228 |
run: make cover |
| 229 |
- uses: codecov/codecov-action@v7 |
| 230 |
with: |
| 231 |
fail_ci_if_error: true |
| 232 |
verbose: true |
| 233 |
token: ${{ secrets.CODECOV_TOKEN }} |