{"id":16218150,"url":"https://github.com/quasilyte/go-n2o","last_synced_at":"2026-01-20T11:32:48.133Z","repository":{"id":85823252,"uuid":"142625718","full_name":"quasilyte/go-n2o","owner":"quasilyte","description":"Go external optimizer.","archived":false,"fork":false,"pushed_at":"2018-08-13T11:52:01.000Z","size":8,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T19:51:20.729Z","etag":null,"topics":["go","golang","optimizer","source-code"],"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/quasilyte.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":"2018-07-27T21:38:25.000Z","updated_at":"2018-09-21T09:16:58.000Z","dependencies_parsed_at":"2023-03-13T06:54:05.254Z","dependency_job_id":null,"html_url":"https://github.com/quasilyte/go-n2o","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quasilyte/go-n2o","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-n2o","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-n2o/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-n2o/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-n2o/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quasilyte","download_url":"https://codeload.github.com/quasilyte/go-n2o/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasilyte%2Fgo-n2o/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28602462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T10:46:13.255Z","status":"ssl_error","status_checked_at":"2026-01-20T10:42:51.865Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["go","golang","optimizer","source-code"],"created_at":"2024-10-10T11:48:44.269Z","updated_at":"2026-01-20T11:32:48.116Z","avatar_url":"https://github.com/quasilyte.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# n2o: nitrous boost for Go\n\n## Quick overview\n\nYou start by writing ordinary Go code.\nThen you spot some execution path that requires optimizations, the hot one.\n\n```go\nfunc array8sum(xs *[8]int) int {\n\ttotal := 0\n\tfor _, x := range xs {\n\t\ttotal += x\n\t}\n\treturn total\n}\n```\n\nSuppose you think that loop unrolling might help.\nInstead of doing this:\n\n```go\nfunc array8sum(xs *[8]int) int {\n\ttotal := 0\n\ttotal += xs[0]\n\ttotal += xs[1]\n\ttotal += xs[2]\n\ttotal += xs[3]\n\ttotal += xs[4]\n\ttotal += xs[5]\n\ttotal += xs[6]\n\ttotal += xs[7]\n\treturn total\n}\n```\n\nYou can do this:\n\n```go\nfunc array8sum(xs *[8]int) int {\n\ttotal := 0\n\t//n2o: unroll\n\tfor _, x := range xs {\n\t\ttotal += x\n\t}\n\treturn total\n}\n```\n\nAnd you get best of two worlds:\n1. Readability of the initial version.\n2. Performance of the optimized (unrolled) code.\n\nThere are other optimizations that can be performed by the `n2o`.\nFor example, you may ask to apply all sensible optimizations to the function:\n\n```go\n// Can also use func/size to optimize for code size.\n//n2o: func/speed\nfunc array8sum(xs *[8]int) int {\n\ttotal := 0\n\tfor _, x := range xs {\n\t\ttotal += x\n\t}\n\treturn total\n}\n```\n\nRead docs to know more about supported directives and their meaning.\n\nBasically, you write Go and then improve performance by optimizer hints, instead of doing dirty work by yourself.\n\n## Optimizations\n\nPlease note that some optimizations may be dangerous when used inappropriately.\n\nFor example, one should not use `deadcode` when unsure that such code path is\nnever executed in the production environment.\nThis is as dangerous as turning off asserts in C and alike, caveat emptor.\n\nFor your convenience, such unsafe optimizations are listed in a separate list.\n\n### Statement/expression local\n\nSome optimizations are applied to the particular statement or expression:\n\n**Safe optimizations**:\n\n* `inline` - force function inlining at the specified call site.\n* `unroll` - unroll a whole loop or make it execute several steps at each iteration.\n\n**Unsafe optimizations**:\n\n* `deadcode` - replace expression or statement that is believed to be \"dead\" during execution.\n\n### Function attributes\n\nOn the function level, there are various optimization attributes that affect\nwhole function body.\n\n```go\n//n2o: inline\n// Force function inlining at the every call site, even if `gc` compiler\n// does not consider function as inlineable candidate.\n// If possible, n2o may transform function body to make function\n// inlineable by `gc` itself, otherwise it does inlining on its own.\nfunc example() {}\n```\n\nThere are also `speed` and `size` optional attributes that can't be used together:\n\n```go\n//n2o: size\n// Try to make function more compact by applying various optimizations to its body.\nfunc optimizedForSize() {}\n\n//n2o: speed\n// Try to make function run faster by applying various optimizations to its body.\nfunc optimizedForExecutionTime() {}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Fgo-n2o","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquasilyte%2Fgo-n2o","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasilyte%2Fgo-n2o/lists"}