Closed qkreltms closed 3 years ago
Is your feature request related to a problem? Please describe. You can improve performance by using Map instead of object when adding, reading listeners.
test('performance', () =>{ const listenMiddleware = createMiddleware(); let cnt = 0; console.time() for (let i=0;i<100;i++) { listenMiddleware.addListener('TEST', () => { cnt += 1; }); } console.timeEnd() console.time() const middleware = listenMiddleware(mockStore)(mockNext); middleware({ type: 'TEST' }); console.timeEnd() expect(Object.keys(listenMiddleware.listeners).length).toBe(100); expect(cnt).toBe(100); })
test('performance', () => { const listenMiddleware = createMiddleware(); let cnt = 0; let t0 = performance.now() for (let i=0;i<100;i++) { listenMiddleware.addListener('TEST', () => { cnt += 1; }); } let t1 = performance.now() console.log(t1-t0) t0 = performance.now() const middleware = listenMiddleware(mockStore)(mockNext); middleware({ type: 'TEST' }); t1 = performance.now() console.log(t1-t0) expect(listenMiddleware.listeners.size).toBe(100); expect(cnt).toBe(100); });
Is your feature request related to a problem? Please describe. You can improve performance by using Map instead of object when adding, reading listeners.
Test scripts
Object
Map