Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty slow while removing one-by-one #908

Open
qiangbro opened this issue Mar 1, 2022 · 1 comment
Open

Pretty slow while removing one-by-one #908

qiangbro opened this issue Mar 1, 2022 · 1 comment
Labels

Comments

@qiangbro
Copy link

qiangbro commented Mar 1, 2022

i have a real time system, i need to add/remove items one-by-one from the db, here's my example:

    let t;

    let alarms = [];
    for (let i = 0; i < 10000; i++) {
        alarms.push({id: i, name: 'hello' + i});
    }

    let db = new loki('exampleDB');
    let alarmCollection = db.addCollection('myAlarms', {indices: ['id']});

    console.log(`开始插入。。。`)
    t = Date.now();
    alarms.forEach(obj => alarmCollection.insert(obj));
    console.log(`完成插入 耗时${(Date.now() - t) / 1000}s alarmCollection.count=${alarmCollection.count()}`);


    console.log('开始删除 size=' + alarms.length)
    t = Date.now();
    alarms.forEach(obj => alarmCollection.findAndRemove({id: obj.id}));
    console.log(`完成删除 耗时${(Date.now() - t) / 1000}s, alarmCollection.count=${alarmCollection.count()}`);

result:

开始插入。。。
完成插入 耗时0.011s alarmCollection.count=10000
开始删除 size=10000
完成删除 耗时2.731s, alarmCollection.count=0

as we can see, it took pretty much time to remove items from the collection one by one.

Any idea to improve the performance for removing one-by-one?

@qiangbro qiangbro changed the title remove one-by-one pretty slow Pretty slow while removing one-by-one Mar 1, 2022
@stale
Copy link

stale bot commented Apr 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant