{"id":18013420,"url":"https://github.com/milly/denops-batch-accumulate","last_synced_at":"2025-04-04T14:24:02.437Z","repository":{"id":250535470,"uuid":"830909520","full_name":"Milly/denops-batch-accumulate","owner":"Milly","description":"Library for denops plugin development. `accumulate` resolves combined multiple denops calls.","archived":false,"fork":false,"pushed_at":"2024-08-03T13:38:05.000Z","size":80,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T14:44:19.405Z","etag":null,"topics":["vim-denops"],"latest_commit_sha":null,"homepage":"https://jsr.io/@milly/denops-batch-accumulate","language":"TypeScript","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/Milly.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":"2024-07-19T08:55:52.000Z","updated_at":"2024-08-03T13:38:06.000Z","dependencies_parsed_at":"2024-08-03T01:17:04.986Z","dependency_job_id":"eec939d1-fae4-4ecc-9735-9a415896be34","html_url":"https://github.com/Milly/denops-batch-accumulate","commit_stats":null,"previous_names":["milly/denops-batch-accumulate"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Fdenops-batch-accumulate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Fdenops-batch-accumulate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Fdenops-batch-accumulate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milly%2Fdenops-batch-accumulate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Milly","download_url":"https://codeload.github.com/Milly/denops-batch-accumulate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247191552,"owners_count":20898954,"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":["vim-denops"],"created_at":"2024-10-30T03:21:30.459Z","updated_at":"2025-04-04T14:24:02.417Z","avatar_url":"https://github.com/Milly.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# denops-batch-accumulate\n\n[![license:MIT](https://img.shields.io/github/license/Milly/denops-batch-accumulate?style=flat-square)](LICENSE)\n[![jsr](https://jsr.io/badges/@milly/denops-batch-accumulate)](https://jsr.io/@milly/denops-batch-accumulate)\n[![codecov](https://codecov.io/gh/Milly/denops-batch-accumulate/graph/badge.svg?token=76N25YHGZO)](https://codecov.io/gh/Milly/denops-batch-accumulate)\n\ndenops-batch-accumulate is helper library for [Denops][].\n\n`accumulate` aggregates all denops functions called during the current task's\nexecution and resolves them in a single RPC call.\n\nNote that functions with side effects should be avoided, and if you do, the\norder in which you call them should be carefully considered.\n\n[Denops]: https://github.com/vim-denops/denops.vim\n\n## Example\n\n```typescript\nimport { assertType, IsExact } from \"jsr:@std/testing/types\";\nimport { Denops } from \"jsr:@denops/core\";\nimport * as fn from \"jsr:@denops/std/function\";\nimport { accumulate } from \"jsr:@milly/denops-batch-accumulate\";\n\nexport async function main(denops: Denops): Promise\u003cvoid\u003e {\n  const results = await accumulate(denops, async (denops) =\u003e {\n    const lines = await fn.getline(denops, 1, \"$\");\n    return await Promise.all(lines.map(async (line, index) =\u003e {\n      const keyword = await fn.matchstr(denops, line, \"\\\\k\\\\+\");\n      const len = await fn.len(denops, keyword);\n      return {\n        lnum: index + 1,\n        keyword,\n        len,\n      };\n    }));\n  });\n\n  assertType\u003c\n    IsExact\u003c\n      typeof results,\n      { lnum: number; keyword: string; len: number }[]\n    \u003e\n  \u003e(true);\n}\n```\n\nIn the case of the example, the following 3 RPCs are called.\n\n1. RPC call to `getline`.\n2. Multiple `matchstr` calls in one RPC.\n3. Multiple `len` calls in one RPC.\n\n## Why use `accumulate()` instead of `collect()` of `@denops/std/batch`?\n\nThe above example can be rewritten using `collect()`, but this is less intuitive\nbecause you need to get intermediate results when you want to generate a complex\nobject as a result.\n\n```typescript\nimport { assertType, IsExact } from \"jsr:@std/testing/types\";\nimport { Denops } from \"jsr:@denops/core\";\nimport * as fn from \"jsr:@denops/std/function\";\nimport { collect } from \"jsr:@denops/std/batch\";\n\nexport async function main(denops: Denops): Promise\u003cvoid\u003e {\n  const lines = await fn.getline(denops, 1, \"$\");\n  const keywords = await collect(\n    denops,\n    (denops) =\u003e lines.map((line) =\u003e fn.matchstr(denops, line, \"\\\\k\\\\+\")),\n  );\n  const lens = await collect(\n    denops,\n    (denops) =\u003e keywords.map((keyword) =\u003e fn.len(denops, keyword)),\n  );\n  const results = keywords.map((keyword, index) =\u003e ({\n    lnum: index + 1,\n    keyword,\n    len: lens[index],\n  }));\n\n  assertType\u003c\n    IsExact\u003c\n      typeof results,\n      { lnum: number; keyword: string; len: number }[]\n    \u003e\n  \u003e(true);\n}\n```\n\n## Benchmark\n\nIt runs as fast as `collect()`.\n\n```\n\u003e deno task bench\nTask bench deno bench -A\ncpu: 12th Gen Intel(R) Core(TM) i7-1260P\nruntime: deno 1.45.0 (x86_64-pc-windows-msvc)\n\nfile:///D:/work/vim/denops-batch-accumulate/batch/accumulate_bench.ts\nbenchmark                           time (avg)        iter/s             (min … max)       p75       p99      p995\n------------------------------------------------------------------------------------ -----------------------------\n\ngroup vim\nwithout batch                      118.61 ms/iter           8.4   (91.95 ms … 159.5 ms) 123.95 ms 159.5 ms 159.5 ms\n@denops/std/batch/collect           15.49 ms/iter          64.6   (13.18 ms … 23.86 ms) 14.74 ms 23.86 ms 23.86 ms\n@milly/denops-batch-accumulate      15.59 ms/iter          64.1   (14.49 ms … 17.79 ms) 15.96 ms 17.79 ms 17.79 ms\n\nsummary\n  @milly/denops-batch-accumulate\n   1.01x slower than @denops/std/batch/collect\n   7.61x faster than without batch\n\ngroup nvim\nwithout batch                      128.08 ms/iter           7.8 (111.96 ms … 198.39 ms) 128.63 ms 198.39 ms 198.39 ms\n@denops/std/batch/collect           14.87 ms/iter          67.3    (11.7 ms … 19.47 ms) 16.27 ms 19.47 ms 19.47 ms\n@milly/denops-batch-accumulate      14.02 ms/iter          71.3    (11.91 ms … 19.8 ms) 14.82 ms 19.8 ms 19.8 ms\n\nsummary\n  @milly/denops-batch-accumulate\n   1.06x faster than @denops/std/batch/collect\n   9.14x faster than without batch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilly%2Fdenops-batch-accumulate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilly%2Fdenops-batch-accumulate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilly%2Fdenops-batch-accumulate/lists"}