Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmhodges/copyfighter
Statically analyzes Go code and reports functions that are passing large structs by value
https://github.com/jmhodges/copyfighter
Last synced: 3 months ago
JSON representation
Statically analyzes Go code and reports functions that are passing large structs by value
- Host: GitHub
- URL: https://github.com/jmhodges/copyfighter
- Owner: jmhodges
- Created: 2015-11-12T21:51:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-25T06:13:34.000Z (over 3 years ago)
- Last Synced: 2024-06-18T20:09:00.209Z (5 months ago)
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 200
- Watchers: 4
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
copyfighter
===========Copyfighter statically analyzes Go code and reports functions that are passing
large structs by value. It helps you help your code.Every Go function call copies the values given to it, including structs. When
large structs are passed around without using a pointer to them, the copying of
new data in memory causes more allocations and more work for your garbage
collector.Copyfighter's static analysis will identify where large structs, without
pointers, are being used as method receivers, function parameters and return
values.Install with `go get` or similar.
Example output
---------------
$ copyfighter /gopath/path/to/pkg
# parameter 'f' at index 0 should be made into a pointer
func CallsFoo(f Foo)
# receiver, and parameter 'o' at index 0 should be made into pointers
func (Foo).OnOtherToo(o other)
# receiver should be made into a pointer
func (other).OnStruct()
# receiver should be made into a pointer
func (other).OnStruct2()$ copyfighter -max 32 path/to/pkg
# parameter 'f' at index 0 should be made into a pointer
func CallsFoo(f Foo)# receiver should be made into a pointer
func (Foo).OnOtherToo(o other)Defaults And Flags
------------------By default, copyfighter assumes structs wider than 16 bytes (two words on x86\_64) should
not be copied. This can be adjusted with the `-max` flag. `max` should typically
be set to some multiple of the word size. You can also adjust the word size and alignment offset for your preferred architecture with `-wordSize` and `-maxAlign`.Flags like `-max` have to go before the package name.
FAQ
---Why not just use Go's heap profiler to fix these problems when they show up?
Because copyfighter can find problems before you put your code in production. It's nice to prevent issues before they matter.