{"id":18379006,"url":"https://github.com/tnfe/limu","last_synced_at":"2025-04-09T05:12:33.223Z","repository":{"id":48382369,"uuid":"371955394","full_name":"tnfe/limu","owner":"tnfe","description":"High performance immutable lib alternative to immer with the same api, based on shallow copy on read and mark modified on write mechanism.","archived":false,"fork":false,"pushed_at":"2024-09-19T09:55:59.000Z","size":3084,"stargazers_count":241,"open_issues_count":1,"forks_count":14,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-02T04:04:57.541Z","etag":null,"topics":["fast","high-perfomance","immutable","immutablejs"],"latest_commit_sha":null,"homepage":"https://tnfe.github.io/limu","language":"JavaScript","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/tnfe.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":"2021-05-29T11:28:13.000Z","updated_at":"2025-03-18T08:33:33.000Z","dependencies_parsed_at":"2024-11-06T00:37:20.144Z","dependency_job_id":"e84d9e6a-bef4-4f76-916e-6946ac548168","html_url":"https://github.com/tnfe/limu","commit_stats":{"total_commits":64,"total_committers":3,"mean_commits":"21.333333333333332","dds":0.265625,"last_synced_commit":"959926df0905e3dfa1c31edf7dfea3ac7d4dca22"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Flimu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Flimu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Flimu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Flimu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tnfe","download_url":"https://codeload.github.com/tnfe/limu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980844,"owners_count":21027808,"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":["fast","high-perfomance","immutable","immutablejs"],"created_at":"2024-11-06T00:36:40.733Z","updated_at":"2025-04-09T05:12:33.194Z","avatar_url":"https://github.com/tnfe.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"## limu 🍋\n\n`limu` is short for **love immutable**, born for efficient creation and operation of immutable object, based on shallow copy on read and mark modified on write mechanism.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://concentjs.github.io/concent-doc\"\u003e\n    \u003cimg width=\"260\" src=\"https://raw.githubusercontent.com/fantasticsoul/assets/master/limu/limu.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nIt is fast, It is nearly more than **2 or 20** times faster than `immer` in different situations. Click this [online perf demo](https://codesandbox.io/s/limu-simple-perf-case-ycky1t?file=/src/index.js) to review the amazing result.\n\n\u003e No freeze by default, limu is 10 times or more faster than Immer in most scenarios\n\n- Debugging friendly, view draft directly anytime without `current`.\n- Smaller package, only 4.3kb gzip.\n- No freeze by default, faster than `immer` in different situations.\n- Natural Support for map and Set.\n\n\u003e Pay attention, limu can only run on JavaScript runtime that supports proxy\n\n## Performance ⚡️\n\nNo freeze by default, limu is 10 times or more faster than Immer in most scenarios after 3.7 version, limu is now the fastest immutable js lib of all ( faster than immer and mutative ).\n\n[test 1](https://github.com/tnfe/limu/blob/main/benchmark/opBigData.js) (inspired by this [immer case](https://github.com/immerjs/immer/blob/main/__performance_tests__/add-data.mjs) ) ![](https://user-images.githubusercontent.com/7334950/257369962-c0577e96-cb2c-48cb-8f65-c11979bfd506.png)\n\n[test 2](https://github.com/tnfe/limu/blob/main/benchmark/caseReadWrite.js) ![test 2](https://user-images.githubusercontent.com/7334950/257380995-1bfc3652-1730-4ecd-ba1b-adaddd3db98d.png)\n\nThe performance testing process is as follows\n\n```bash\ngit clone https://github.com/tnfe/limu\ncd limu\nnpm i\ncd benchmark\nnpm i\nnode opBigData.js // trigger test execution, the console echoes the result\n# or\nnode caseOnlyRead.js\nnpm run s1\nnpm run s2\nnpm run s3\nnpm run s4\n```\n\nYou are very welcome to submit your test to the [benchmark directory](https://github.com/tnfe/limu/tree/main/benchmark) or [test directory](https://github.com/tnfe/limu/tree/main/test)\n\n## Quick Start\n\ninstall\n\n```bash\nnpm i limu\n```\n\napis\n\n```js\nimport { produce, createDraft, finishDraft } from 'limu';\n```\n\n### produce\n\n```js\nconst baseState = {\n  a: 1,\n  b: [1, 2, 3],\n  c: {\n    c1: { n: 1 },\n    c2: { m: 2 },\n  },\n};\nconst nextState = produce(baseState, (draft) =\u003e {\n  draft.a = 2;\n  draft.b['2'] = 100;\n});\n\nconsole.log(nextState === baseState); // false\nconsole.log(nextState.a === baseState.a); // false\nconsole.log(nextState.b === baseState.b); // false\nconsole.log(nextState.c === baseState.c); // true\n```\n\nCurrying call\n\n```js\nconst producer = produce((draft) =\u003e {\n  draft.a = 2;\n  draft.b['2'] = 100;\n});\nconst nextState = producer(baseState);\n```\n\n### createDraft, finishDraft\n\n```js\nconst draft = createDraft(baseState);\ndraft.a = 2;\ndraft.b = [];\nconst nextState = finishDraft(draft);\n\nconsole.log(nextState === baseState); // false\nconsole.log(nextState.a === baseState.a); // false\nconsole.log(nextState.b === baseState.b); // false\nconsole.log(nextState.c === baseState.c); // true\n```\n\n## Experience limu on the console\n\n![logo](https://raw.githubusercontent.com/fantasticsoul/assets/master/limu/limu-benchmark.jpg)\n\nAs limu is an immutable js library based on shallow copy on read and mark modified on write. Based on this mechanism, so it is more friendly to debugging. You can copy the following code to the console experience\n\nthere are 2 ways to quickly experience limu and compare limu with immer.\n\n- 1, open [limu doc site](https://tnfe.github.io/limu/) and right-click to open the console.\n\n- 2, visit [unpkg](https://unpkg.com/), right-click to open the console, and then paste the following code to load js\n\n```ts\nfunction loadJs(url) {\n  const dom = document.createElement('script');\n  dom.src = url;\n  document.body.appendChild(dom);\n}\n\nloadJs('https://unpkg.com/limu@3.5.5/dist/limu.min.js'); // load limu umd bundle\nloadJs('https://unpkg.com/immer@9.0.21/dist/immer.umd.production.min.js'); // load immer umd bundle\n```\n\nThen you can paste below codes to run\n\n- case 1\n\n```ts\nfunction oneCase(produce) {\n  const demo = { info: Array.from(Array(10000).keys()) };\n  produce(demo, (draft) =\u003e {\n    draft.info[2000] = 0;\n  });\n}\n\nfunction runBenchmark(produce, label) {\n  const start = Date.now();\n  const limit = 100;\n  for (let i = 0; i \u003c limit; i++) {\n    oneCase(produce);\n  }\n  console.log(`${label} avg spend ${(Date.now() - start) / limit} ms`);\n}\n\nfunction run() {\n  immer.setAutoFreeze(false);\n  runBenchmark(immer.produce, 'immer,');\n  runBenchmark(limu.produce, 'limu,');\n}\n```\n\n- case 2\n\n```ts\nlib = window.limu; // or lib = window.immer\nconst base = {\n  a: 1,\n  b: { b1: 1, b2: 2, b3: { b31: 1 } },\n  c: [1, 2, 3],\n  d: { d1: 1000 },\n};\nconst draft = lib.createDraft(base);\ndraft.a = 200;\ndraft.b.b1 = 100;\nconsole.log(draft);\ndraft.c.push(4);\nconst final = lib.finishDraft(draft);\nconsole.log(base === final); // false\nconsole.log(base.a === final.a); // false\nconsole.log(base.b === final.b); // false\nconsole.log(base.b.b3 === final.b.b3); // true\nconsole.log(base.c === final.c); // false\nconsole.log(base.d === final.d); //true\n```\n\nHigher observability will greatly improve the development and debugging experience, as shown in the figure below, after unfolding the `limu` draft, you can observe all data nodes of the draft in real time\n\n\u003cimg width=\"574\" alt=\"image\" src=\"https://github.com/unadlib/mutative/assets/7334950/2f90b07d-e2e3-4104-916c-8c0add935b41\"\u003e\n\nAnd the immer or mutative expansion is like this \u003cimg width=\"618\" alt=\"image\" src=\"https://github.com/unadlib/mutative/assets/7334950/44500c66-d691-4d29-b856-fa490d2bdf8f\"\u003e\n\n## License\n\nCopyright (c) Tencent Corporation. All rights reserved.\n\nLimu is released under the MIT License(https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnfe%2Flimu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftnfe%2Flimu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnfe%2Flimu/lists"}