iOS Safari 目前默认在 120Hz 屏幕上将 requestAnimationFrame 的频率限制为 60Hz,除非用户手动开启开发者设置中的“偏好接近 60fps 的页面渲染更新”标志 1。针对这一瓶颈,开发者 Devon Govett 发表技术分析,展示了一套结合输入与渲染优化的方案,旨在让 Web 应用在 iPhone 上获得接近原生应用的高刷新率体验 1。该方案的核心在于利用合成器线程处理高频输入,并借助 OffscreenCanvas API 跳过主线程等待,从而突破默认的帧率上限 1。
在输入层面,该技术通过创建一个不可见的滚动容器作为“控制器”,利用合成器线程处理滚动事件以获取高达 120Hz 的位置数据 1。为解决进程间通信(IPC)可能导致的丢包问题,方案中引入了空的 requestAnimationFrame 循环来强制刷新;同时,通过缩放 DOM 元素利用子像素精度,克服了潜在的数据精度丢失挑战 1。
在渲染层面,当调用 canvas.transferControlToOffscreen() 后,WebKit 遵循 HTML 规范建议,在 OffscreenCanvas 推送帧时跳过对主线程渲染路径的等待,从而实现超越 60FPS 的流畅度 1。实测数据显示,在 iPhone 18 Pro 上使用此方案进行拖拽交互时,平均帧率达到 118 FPS,而传统的指针事件方法仅为 60 FPS;即便在低电量模式下,该方案也能维持 60 FPS 的表现 1。
尽管效果显著,作者指出该技巧依赖于 Apple 当前的浏览器行为,存在被后续更新封堵的风险 1。Apple 有权在未来要求 OffscreenCanvas 必须等待主线程渲染,从而使此优化失效 1。Govett 表示,他更希望 Apple 能直接原生支持 Web 内容的 ProMotion 技术,而非依赖此类变通手段 1。
Devon Govett has published a technical analysis detailing how to bypass iOS Safari's default frame rate limits, enabling web applications to achieve native-like interactions at high refresh rates 1. By default, iOS Safari restricts requestAnimationFrame calls to 60Hz on 120Hz screens, unless users manually disable the 'Prefer Page Rendering Updates near 60fps' flag in developer settings 1. The proposed solution circumvents this cap by leveraging specific browser mechanisms to unlock full ProMotion performance for web content.
The approach combines two primary techniques: optimized input handling and a specialized rendering pathway 1. To capture high-frequency data, Govett creates an invisible scrolling container that acts as a "controller," utilizing the compositor thread to process scroll events and retrieve position updates at up to 120Hz 1. This method addresses IPC packet loss by forcing flushes with empty requestAnimationFrame loops and mitigates precision loss by scaling DOM elements to exploit sub-pixel accuracy 1. For rendering, the technique employs the canvas.transferControlToOffscreen() API 1. When invoked, WebKit follows HTML specification recommendations to skip waiting for the main thread's rendering path when OffscreenCanvas pushes frames, effectively breaking the 60FPS barrier 1.
Performance tests conducted on an iPhone 18 Pro showed that drag interactions using this architecture achieved an average frame rate of 118 FPS, compared to 60 FPS with traditional pointer event methods 1. The workaround maintained a consistent 60 FPS even in low power mode 1. However, Govett notes that the strategy relies on current Apple browser behaviors and faces the risk that future updates could invalidate the technique by requiring OffscreenCanvas to wait for the main thread 1. The author expressed a preference for Apple to natively support ProMotion for web content rather than depending on such workarounds 1.
评论
还没有评论,欢迎留下第一条。