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

add benchmarks to compare protocompile perf and memory usage against other compilers #64

Merged
merged 5 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ jobs:
restore-keys: ${{ runner.os }}-protocompile-ci-
- name: Test
run: make test
- name: Benchmarks
# no need to run benchmarks for every Go version
if: matrix.go-version == '1.19.x'
run: make benchmarks
- name: Lint
# Often, lint & gofmt guidelines depend on the Go version. To prevent
# conflicting guidance, run only on the most recent supported version.
# For the same reason, only check generated code on the most recent
# supported version.
if: matrix.go-version == '1.19.x'
run: make checkgenerate && make lint
run: make checkgenerate lint
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ issues:
# Don't ban use of fmt.Errorf to create new errors, but the remaining
# checks from err113 are useful.
- "err113: do not define dynamic errors.*"
exclude-rules:
# Benchmarks can't be run in parallel
- path: benchmark_test\.go
linters:
- paralleltest
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TOOLS_MOD_DIR := ./internal/tools
UNAME_OS := $(shell uname -s)
UNAME_ARCH := $(shell uname -m)

# NB: this must be kept in sync with constant in internal/benchmarks.
PROTOC_VERSION ?= 21.7
PROTOC_DIR := $(abspath ./internal/testdata/protoc/$(PROTOC_VERSION))
PROTOC := $(PROTOC_DIR)/bin/protoc
Expand Down Expand Up @@ -50,6 +51,10 @@ clean: ## Delete intermediate build artifacts
test: build ## Run unit tests
$(GO) test -vet=off -race -cover ./...

.PHONY: benchmarks
benchmarks: build ## Run benchmarks
cd internal/benchmarks && $(GO) test -bench=. -benchmem -v ./...

.PHONY: build
build: generate ## Build all packages
$(GO) build ./...
Expand All @@ -60,12 +65,14 @@ install: ## Install all binaries

.PHONY: lint
lint: $(BIN)/golangci-lint ## Lint Go
$(GO) vet ./...
$(GO) vet ./... ./internal/benchmarks/...
$(BIN)/golangci-lint run
cd internal/benchmarks && $(BIN)/golangci-lint run

.PHONY: lintfix
lintfix: $(BIN)/golangci-lint ## Automatically fix some lint errors
$(BIN)/golangci-lint run --fix
cd internal/benchmarks && $(BIN)/golangci-lint run --fix

.PHONY: generate
generate: $(BIN)/license-header $(BIN)/goyacc test-descriptors ## Regenerate code and licenses
Expand Down
11 changes: 11 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ type Compiler struct {
// concludes. Similarly, if they already have source code info but this flag
// is false, existing info will be left in place.
SourceInfoMode SourceInfoMode

// If true, ASTs are retained in compilation results for which an AST was
// constructed. So any linker.Result value in the resulting compiled files
// will have an AST, in addition to descriptors. If left false, the AST
// will be removed as soon as it's no longer needed. This can help reduce
// total memory usage for operations involving a large number of files.
RetainASTs bool
}

// SourceInfoMode indicates how source code info is generated by a Compiler.
Expand Down Expand Up @@ -518,6 +525,10 @@ func (t *task) link(parseRes parser.Result, deps linker.Files) (linker.File, err
}
file.PopulateSourceCodeInfo()
}

if !t.e.c.RetainASTs {
file.RemoveAST()
}
Comment on lines +529 to +531
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one significant improvement for memory usage in protocompile. It allows the AST to be dropped early in the process, so a large compilation doesn't accumulate a large amount of ASTs pinned on the heap.

return file, nil
}

Expand Down
7 changes: 7 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go 1.19

use (
.
./internal/benchmarks
./internal/tools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

)
183 changes: 183 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

Loading