perf(map): reduce tile snapshot work during zoom

This commit is contained in:
2026-07-30 12:50:33 +08:00
parent 82e75c03d0
commit 1b2a7f4fb8
5 changed files with 592 additions and 161 deletions
@@ -0,0 +1,46 @@
import { createTileSnapshotScheduler } from "./tileSnapshotScheduler";
describe("createTileSnapshotScheduler", () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
it("defers and coalesces tile snapshots until movement ends", () => {
const publish = jest.fn();
const scheduler = createTileSnapshotScheduler({ publish, wait: 50 });
scheduler.beginMove();
scheduler.markDirty();
scheduler.markDirty();
jest.advanceTimersByTime(100);
expect(publish).not.toHaveBeenCalled();
scheduler.endMove();
jest.advanceTimersByTime(49);
expect(publish).not.toHaveBeenCalled();
jest.advanceTimersByTime(1);
expect(publish).toHaveBeenCalledTimes(1);
});
it("batches settled tile arrivals and cancels pending work", () => {
const publish = jest.fn();
const scheduler = createTileSnapshotScheduler({ publish, wait: 50 });
scheduler.markDirty();
jest.advanceTimersByTime(25);
scheduler.markDirty();
jest.advanceTimersByTime(49);
expect(publish).not.toHaveBeenCalled();
jest.advanceTimersByTime(1);
expect(publish).toHaveBeenCalledTimes(1);
scheduler.markDirty();
scheduler.cancel();
jest.runAllTimers();
expect(publish).toHaveBeenCalledTimes(1);
});
});