{"id":23960393,"url":"https://github.com/m0t9/arrcopy","last_synced_at":"2025-04-23T04:21:22.009Z","repository":{"id":271012912,"uuid":"911708883","full_name":"m0t9/arrcopy","owner":"m0t9","description":"Go linter prohibiting for-range over arrays copies","archived":false,"fork":false,"pushed_at":"2025-01-06T11:43:22.000Z","size":4691,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T22:04:41.198Z","etag":null,"topics":["arrays","go","linter","optimization","performance-tuning"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m0t9.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-03T16:53:36.000Z","updated_at":"2025-01-08T08:54:31.000Z","dependencies_parsed_at":"2025-01-04T19:39:44.931Z","dependency_job_id":null,"html_url":"https://github.com/m0t9/arrcopy","commit_stats":null,"previous_names":["m0t9/arrcopy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0t9%2Farrcopy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0t9%2Farrcopy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0t9%2Farrcopy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m0t9%2Farrcopy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m0t9","download_url":"https://codeload.github.com/m0t9/arrcopy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250367208,"owners_count":21418844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","go","linter","optimization","performance-tuning"],"created_at":"2025-01-06T19:27:52.636Z","updated_at":"2025-04-23T04:21:21.992Z","avatar_url":"https://github.com/m0t9.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arrcopy\n\n[![coverage](https://raw.githubusercontent.com/m0t9/arrcopy/badges/.badges/master/coverage.svg)](https://github.com/m0t9/arrcopy/actions/workflows/.testcoverage.yml)\n[![build](https://github.com/m0t9/arrcopy/actions/workflows/go.yml/badge.svg)](https://github.com/m0t9/arrcopy/actions/workflows/go.yml)\n\nSimple Go linter prohibiting `for-range` iteration over array copy.\n\n## Details\n\nThe `range` operator creates a copy of the array before iterating over it.\nIn case of heavyweight arrays it may lead to significant performance degradation.\nOne can see explanation with clear benchmarks [here](https://medium.com/@haaawk/i-thought-i-understood-how-iteration-over-an-array-works-but-apparently-not-in-golang-441a7abd6540)\n\n## Usage\n\n### Installation\n\n`go install github.com/m0t9/arrcopy/cmd/...@latest`\n\n### Running\n\nLinter is compatible with `go vet`\n\n`go vet -vettool=$(which arrcopy) ./...` \n\n## Optimization example \n\nThe inefficiency of array copying can be shown in the benchmark below\n\n```go\nfunc BenchmarkArrayIteration(b *testing.B) {\n\tconst Size = 1000000\n\ttype Item struct {\n\t\ts      string\n\t\tsubarr [5]int64\n\t\tsl     []int\n\t\tp      *int\n\t}\n\n\tb.Run(\"over copy\", func(b *testing.B) {\n\t\tfor i := 0; i \u003c b.N; i++ {\n\t\t\tb.StopTimer()\n\t\t\tarr := [Size]Item{}\n\t\t\tb.StartTimer()\n\t\t\tfor idx, item := range arr {\n\t\t\t\t_, _ = idx, item\n\t\t\t}\n\t\t}\n\t})\n\n\tb.Run(\"over reference\", func(b *testing.B) {\n\t\tfor i := 0; i \u003c b.N; i++ {\n\t\t\tb.StopTimer()\n\t\t\tarr := [Size]Item{}\n\t\t\tb.StartTimer()\n\t\t\tfor idx, item := range \u0026arr { // added \u0026 before arr\n\t\t\t\t_, _ = idx, item\n\t\t\t}\n\t\t}\n\t})\n}\n```\n\n```\ngoos: darwin\ngoarch: arm64\npkg: github.com/m0t9/arrcopy/cmd/arrcopy\ncpu: Apple M1\nBenchmarkArrayIteration/over_copy-8                   52          21382312 ns/op\nBenchmarkArrayIteration/over_reference-8            3085            382052 ns/op\nPASS\nok      github.com/m0t9/arrcopy/cmd/arrcopy     9.923s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm0t9%2Farrcopy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm0t9%2Farrcopy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm0t9%2Farrcopy/lists"}