{"id":24956951,"url":"https://github.com/toyboot4e/va-bench","last_synced_at":"2025-03-28T20:38:25.316Z","repository":{"id":274202905,"uuid":"922184627","full_name":"toyboot4e/va-bench","owner":"toyboot4e","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-02T05:58:47.000Z","size":448,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:02:00.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toyboot4e.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-25T14:47:45.000Z","updated_at":"2025-02-02T05:58:50.000Z","dependencies_parsed_at":"2025-01-25T17:37:39.618Z","dependency_job_id":null,"html_url":"https://github.com/toyboot4e/va-bench","commit_stats":null,"previous_names":["toyboot4e/va-bench"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyboot4e%2Fva-bench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyboot4e%2Fva-bench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyboot4e%2Fva-bench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toyboot4e%2Fva-bench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toyboot4e","download_url":"https://codeload.github.com/toyboot4e/va-bench/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246100419,"owners_count":20723466,"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":[],"created_at":"2025-02-03T06:41:44.321Z","updated_at":"2025-03-28T20:38:25.288Z","avatar_url":"https://github.com/toyboot4e.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# va-bench\n\nThis repository is for benchmarking the [`vector-algorithms`](https://github.com/erikd/vector-algorithms) package, primarily for PRs.\n\n## Setup\n\n- Install GHC 9.8.4 with LLVM enabled\n- Or, run `direnv allow` if you have Nix Flakes setup\n\n## How to run\n\nBenchmarks can be run with [`just`](https://github.com/casey/just). See [`Justfile`](./Justfile) for the recipes.\n\n## Benchmark results\n\n### 1. `inline-sort`\n\nThe `sort` function in `Intro` module should be marked as `INLINE`, not `INLINEABLE`:\n\n![](./img/inline-sort.png)\n\n### 2. `sort-vs-sort-by`\n\nOther `sort` functions should also be marked as `INLINE` to be as fast as `sortBy compare`:\n\n![](./img/sort-vs-sort-by.png)\n\n### 3. `nub`\n\n`nub` and `nubBy` should be marked as `INLINE`. `nubByMut` should be atleast marked as `INLINEABLE`:\n\n![](./img/nub.png)\n\n## Core output inspection\n\nI'm not a Haskell pro, but let's look into `.dump-prep` files with my best effort:\n\n```sh\n$ cabal clean\n$ just dump\n$ cd dist-newstyle\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/b/inline-sort/opt/build/inline-sort/inline-sort-tmp/bench/InlineSort.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/b/nub/opt/build/nub/nub-tmp/bench/Nub.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/b/sort-vs-sort-by/opt/build/sort-vs-sort-by/sort-vs-sort-by-tmp/bench/SortVsSortBy.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Common.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Common.dyn.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Intro/Inline.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Intro/Inline.dyn.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Intro/StToPrim.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Intro/StToPrim.dyn.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Nub/Inline.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Nub/Inline.dyn.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Nub/Inlineable.dump-prep\nbuild/x86_64-linux/ghc-9.8.4/va-bench-0.1.0.0/opt/build/src/Nub/Inlineable.dyn.dump-prep\n```\n\n### 1. `inline-sort`\n\nLook into `InlineSort.dump-prep`.\n\nThe call to `Data.Vector.Algorithms.Intro.sort` seems like not specialized, as we're seeing `PrimMonad` not `ST`. Especially `$fPrimMonadST0`, it's a dictionary-passing style:\n\n```\n                  case ((Data.Vector.Algorithms.Intro.sort\n                           @(GHC.ST.ST GHC.Prim.RealWorld)\n                           @Data.Vector.Unboxed.Base.MVector\n                           @GHC.Types.Int\n                           (Control.Monad.Primitive.$fPrimMonadST0 @GHC.Prim.RealWorld)\n                           Data.Vector.Unboxed.Base.$fMVectorMVectorInt\n                           GHC.Classes.$fOrdInt\n                           sat_s7Vb)\n                        `cast` (GHC.ST.N:ST[0] \u003cGHC.Prim.RealWorld\u003e_N \u003c()\u003e_R\n                                :: GHC.ST.ST GHC.Prim.RealWorld ()\n                                   ~R# GHC.ST.STRep GHC.Prim.RealWorld ()))\n                         (s'#1_s7Va\n                          `cast` ((GHC.Prim.State#\n                                     (Control.Monad.Primitive.D:R:PrimStateST0[0]\n                                          \u003cControl.Monad.Primitive.PrimState\n                                             (GHC.ST.ST GHC.Prim.RealWorld)\u003e_N\n                                      ; Control.Monad.Primitive.D:R:PrimStateST0[0]\n                                            \u003cGHC.Prim.RealWorld\u003e_N))_R\n                                  :: GHC.Prim.State#\n                                       (Control.Monad.Primitive.PrimState\n                                          (GHC.ST.ST\n                                             (Control.Monad.Primitive.PrimState\n                                                (GHC.ST.ST GHC.Prim.RealWorld))))\n                                     ~R# GHC.Prim.State# GHC.Prim.RealWorld))\n```\n\nThere's no `Data.Vector.Algorithms.Intro.sortBy` call. It seems like inlined (I guess).\n\n### 2. `sort-vs-sort-by`\n\nLook into `SortVsSortBy.dump-prep`. I did not yet, but something similar could be observed.\n\n### 3. `nub`\n\nLook into `Nub.dump-prep`. I did not yet, but something similar could be observed.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoyboot4e%2Fva-bench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoyboot4e%2Fva-bench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoyboot4e%2Fva-bench/lists"}