-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously we were calling bulkUpdate on all participants regardless of whether the fetched participants were actually different from the ones stored in IndexedDB. Since the participant data changes infrequently, we were wasting a lot of CPU cycles on updating identical records. We now filter out using deep equality only those participants that are actually different and only bulkUpdate those. For 10k participants, this leads to ~6x speedup.
- Loading branch information
Showing
5 changed files
with
151 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {deepEqual} from './deep_equal'; | ||
|
||
test('test deepEqual()', () => { | ||
expect(deepEqual(undefined, undefined)).toBe(true); | ||
expect(deepEqual(null, null)).toBe(true); | ||
expect(deepEqual(42, 42)).toBe(true); | ||
expect(deepEqual('foo', 'foo')).toBe(true); | ||
|
||
expect(deepEqual(42, null)).toBe(false); | ||
expect(deepEqual(null, 42)).toBe(false); | ||
|
||
expect(deepEqual([], [])).toBe(true); | ||
expect(deepEqual([1, 2, 3], [1, 2, 3])).toBe(true); | ||
expect(deepEqual([1, 2, 3], [1, 2, 4])).toBe(false); | ||
expect(deepEqual([1, 2, 3], [1, 2])).toBe(false); | ||
expect(deepEqual([1, 2], [1, 2, 3])).toBe(false); | ||
|
||
expect(deepEqual({}, {})).toBe(true); | ||
expect(deepEqual({a: 1, b: 2}, {a: 1, b: 2})).toBe(true); | ||
expect(deepEqual({a: 1, b: 2}, {a: 1, b: 3})).toBe(false); | ||
expect(deepEqual({a: 1, b: 2}, {a: 1})).toBe(false); | ||
expect(deepEqual({a: 1}, {a: 1, b: 2})).toBe(false); | ||
|
||
expect(deepEqual('foo', 'bar')).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export function deepEqual(a: any, b: any): boolean { | ||
if (a === b) { | ||
return true; | ||
} | ||
|
||
if (a === null || b === null) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(a) && Array.isArray(b)) { | ||
return deepEqualArray(a, b); | ||
} | ||
|
||
if (typeof a === 'object' && typeof b === 'object') { | ||
return deepEqualObject(a, b); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function deepEqualArray(a: any[], b: any[]): boolean { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < a.length; i++) { | ||
if (!deepEqual(a[i], b[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function deepEqualObject(a: {[key: string]: any}, b: {[key: string]: any}): boolean { | ||
const keys = Object.keys(a); | ||
if (keys.length !== Object.keys(b).length) { | ||
return false; | ||
} | ||
|
||
for (const key of keys) { | ||
if (!deepEqual(a[key], b[key])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |