Optimizing WebGL Map Rendering with the RAIL Model and Task Scheduler
This article explains how to improve WebGL map performance by applying Google’s RAIL model, synchronizing updates with requestAnimationFrame, and using a task scheduler to defer non‑critical work, ensuring smooth frame rates and responsive interactions.
We discuss applying a task scheduler in a WebGL map engine, using Google’s RAIL performance model as a guiding framework.
RAIL Model Overview
Response: React to user input within 100 ms.
Animation: Target 60 FPS; keep each frame’s processing under 10 ms (leaving ~6 ms for the browser).
Idle: Utilize idle time in 50 ms intervals to prepare work.
Load: Complete the first page load within 1 s so the page is no longer blank.
In the WebGL map implementation we evaluate performance with the RAIL model.
Engine Rendering Phases
Map state changes and some asynchronous operations (e.g., texture creation) are synchronized to each requestAnimationFrame (rAF) frame. The per‑frame script execution can be split into two stages:
Update stage: Update buffers and textures (e.g., bufferData, bufferSubData, texImage2D, texSubImage2D) and optionally clear old data.
Draw stage: Bind buffers, set shader attributes/uniforms, and issue draw calls.
Heavy operations in the update stage (large texture uploads, bulk data updates, clearing old buffers) can cause noticeable stutter.
These update tasks can be deferred: they do not need to finish before the next frame renders, allowing the map to stay responsive even if some elements are temporarily missing.
Task Scheduler Application
The scheduler manages deferred work, executing it at appropriate times without harming overall frame rate.
Scheduler Mechanism
Tasks are classified into two categories:
Normal Job: Short (few milliseconds) high‑priority tasks such as small bufferData or texImage2D calls. They are interleaved into each frame; the scheduler tracks cumulative time and moves remaining tasks to the next frame if the budget is exceeded.
Heavy Job: Longer or less time‑critical tasks (e.g., cache cleanup). They run during idle periods, checking every 50 ms whether the engine is still idle before continuing.
After integrating the scheduler, the execution flow follows the diagram below:
Key Takeaways
Use the RAIL model to evaluate page performance.
Synchronize as many operations as possible with requestAnimationFrame.
Employ a task scheduler to shift non‑critical work to later frames or idle time, preserving smooth map interaction.
Baidu Maps Tech Team
Want to see the Baidu Maps team's technical insights, learn how top engineers tackle tough problems, or join the team? Follow the Baidu Maps Tech Team to get the answers you need.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
