localStorage经常使用会减慢我的网站速度吗? [英] Can localStorage slow down my website when used frequently?

查看:451
本文介绍了localStorage经常使用会减慢我的网站速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发HTML5游戏,我需要知道更新localStorage属性是否经常会降低页面速度。

I'm developing a HTML5 game and I need to know if updating localStorage properties frequently can slow down the page.

我实际上是在存储我的英雄的位置四个localStorage属性(两个用于实际位置,两个用于在碰撞检测系统中使用的过去位置)并每隔1秒更新一次,但我想以60fps 更新它以保存每个英雄移动。

I'm actually storing my hero's position in four localStorage properties (two for the actual position and two for the past position to use in a collision detection system) and updating it every 1 second interval, but I want to update it at 60fps to save every hero movement.

在该频率下使用localStorage会导致性能问题?

Using localStorage in that frequency can result in performance issues?

推荐答案

本地存储将数据存储在用户的硬盘上。读取和写入硬盘驱动器需要的时间比RAM要长一些。

Local storage stores the data on your user's hard drive. It takes a bit longer to read and write to the hard drive than it does to RAM.

从中得出的结论是,您可以通过阅读来优化性能从启动时的本地存储开始,只有在用户注销时才写入。

The conclusion to take away from this is that you could optimize your performance by reading from local storage on start up and only write to it when the user logs out.

现在,无论该优化是否会对您的项目产生重大影响,您都可以拥有要弄明白,并且正如R3tep所说, http://jsperf.com/ 是一个很好的解决方案。

Now, whether or not that optimization will significantly affect your project is something you'll have to figure out, and, as R3tep said, http://jsperf.com/ is a good solution.

我的建议是,无论如何都要优化,只是因为它不那么令人满意,我想,让程序运行速度比没有好处的要慢理由。

My advice, though, is to just go with the optimization anyway, just because it's less "satisfying", I guess, to have a program run more slowly than it could for no good reason.

这篇关于localStorage经常使用会减慢我的网站速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆