refactor/code-splitting #31

Merged
ilia merged 32 commits from refactor/code-splitting into main 2026-04-08 06:34:20 +00:00
8 changed files with 20 additions and 12 deletions
Showing only changes of commit c6dabafd93 - Show all commits

View File

@@ -1,7 +1,7 @@
/** @vitest-environment jsdom */
import { AppliedFontsManager } from './appliedFontsStore.svelte';
import { FontFetchError } from './errors';
import { FontEvictionPolicy } from './fontEvictionPolicy/FontEvictionPolicy';
import { FontEvictionPolicy } from './utils/fontEvictionPolicy/FontEvictionPolicy';
// ── Fake collaborators ────────────────────────────────────────────────────────

View File

@@ -7,15 +7,15 @@ import {
FontFetchError,
FontParseError,
} from './errors';
import { FontBufferCache } from './fontBufferCache/FontBufferCache';
import { FontEvictionPolicy } from './fontEvictionPolicy/FontEvictionPolicy';
import { FontLoadQueue } from './fontLoadQueue/FontLoadQueue';
import {
generateFontKey,
getEffectiveConcurrency,
loadFont,
yieldToMainThread,
} from './utils';
import { FontBufferCache } from './utils/fontBufferCache/FontBufferCache';
import { FontEvictionPolicy } from './utils/fontEvictionPolicy/FontEvictionPolicy';
import { FontLoadQueue } from './utils/fontLoadQueue/FontLoadQueue';
interface AppliedFontsManagerDeps {
cache?: FontBufferCache;

View File

@@ -1,5 +1,5 @@
/** @vitest-environment jsdom */
import { FontFetchError } from '../errors';
import { FontFetchError } from '../../errors';
import { FontBufferCache } from './FontBufferCache';
const makeBuffer = () => new ArrayBuffer(8);

View File

@@ -1,4 +1,4 @@
import { FontFetchError } from '../errors';
import { FontFetchError } from '../../errors';
type Fetcher = (url: string, init?: RequestInit) => Promise<Response>;
@@ -40,7 +40,9 @@ export class FontBufferCache {
async get(url: string, signal?: AbortSignal): Promise<ArrayBuffer> {
// Tier 1: in-memory (fastest, no I/O)
const inMemory = this.#buffersByUrl.get(url);
if (inMemory) return inMemory;
if (inMemory) {
return inMemory;
}
// Tier 2: Cache API
try {

View File

@@ -48,8 +48,12 @@ export class FontEvictionPolicy {
*/
shouldEvict(key: string, now: number): boolean {
const lastUsed = this.#usageTracker.get(key);
if (lastUsed === undefined) return false;
if (this.#pinnedFonts.has(key)) return false;
if (lastUsed === undefined) {
return false;
}
if (this.#pinnedFonts.has(key)) {
return false;
}
return now - lastUsed >= this.#TTL;
}

View File

@@ -1,4 +1,4 @@
import type { FontLoadRequestConfig } from '../../../types';
import type { FontLoadRequestConfig } from '../../../../types';
import { FontLoadQueue } from './FontLoadQueue';
const config = (id: string): FontLoadRequestConfig => ({

View File

@@ -1,4 +1,4 @@
import type { FontLoadRequestConfig } from '../../../types';
import type { FontLoadRequestConfig } from '../../../../types';
/**
* Manages the font load queue and per-font retry counts.
@@ -17,7 +17,9 @@ export class FontLoadQueue {
* @returns `true` if the key was newly enqueued, `false` if it was already present.
*/
enqueue(key: string, config: FontLoadRequestConfig): boolean {
if (this.#queue.has(key)) return false;
if (this.#queue.has(key)) {
return false;
}
this.#queue.set(key, config);
return true;
}