Skip to content

使用 Array.slice 结果出现问题 #15

Open

Description

@LiChangyi

参考一下代码:

import { produce } from 'limu';

let data2 = {
  history: Array.from({ length: 10 }).map(() => ({
    list: Array.from({ length: 10000 }).map((_, i) => ({
      id: i,
    })),
  })),
}

const start = Date.now();
const newData = produce(data2, draft => {
  draft.history = draft.history.slice(1);
})
console.log('slice', Date.now() - start, 'ms', newData);

输出:
slice 1 ms { history: [ ] }

输出保留了 proxy 状态,导致后续使用数据时出现问题。

出问题版本:
^4.1.1

在 3.13.2 版本中未出现问题,但是在 3.13.2 中对于大对象有性能问题,上述脚本耗时: 1220 ms

Activity

  1. fantasticsoul commented on Oct 14, 2025

    @fantasticsoul
    Member

    收到建议,我看下是原因

  2. fantasticsoul commented on Oct 14, 2025

    @fantasticsoul
    Member

    是否用immer测试过,同样情况下相关耗时情况呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions