Skip to content

Commit

Permalink
fix: Adjust font cache to prevent downward spiral on mobile (#2850)
Browse files Browse the repository at this point in the history
This PR fixes a downward spiral that is possible on platforms with a slow couple frames. The `FontCache` font timeout to 500 ms and makes it configurable as a static `FontCache.FONT_TIMEOUT`. This is to help prevent a downward spiral on mobile devices that might take a long while to render a few starting frames causing the cache to repeatedly clear and never recover.
  • Loading branch information
eonarheim authored Dec 21, 2023
1 parent 4832577 commit cbb287a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

-
- Adjusted the `FontCache` font timeout to 400 ms and makes it configurable as a static `FontCache.FONT_TIMEOUT`. This is to help prevent a downward spiral on mobile devices that might take a long while to render a few starting frames causing the cache to repeatedly clear and never recover.

### Updates

Expand Down
3 changes: 2 additions & 1 deletion src/engine/Graphics/FontCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Font } from './Font';
import { FontTextInstance } from './FontTextInstance';

export class FontCache {
public static FONT_TIMEOUT = 500;
private static _LOGGER = Logger.getInstance();
private static _TEXT_USAGE = new Map<FontTextInstance, number>();
private static _TEXT_CACHE = new Map<string, FontTextInstance>();
Expand Down Expand Up @@ -41,7 +42,7 @@ export class FontCache {
const currentHashCodes = new Set<string>();
for (const [textInstance, time] of FontCache._TEXT_USAGE.entries()) {
// if bitmap hasn't been used in 100 ms clear it
if (time + 100 < performance.now()) {
if (time + FontCache.FONT_TIMEOUT < performance.now()) {
FontCache._LOGGER.debug(`Text cache entry timed out ${textInstance.text}`);
deferred.push(textInstance);
textInstance.dispose();
Expand Down

0 comments on commit cbb287a

Please sign in to comment.