在每个浏览器中分配__proto__的具体影响是什么? [英] What is the specific impact of assigning __proto__ in each browser?

查看:140
本文介绍了在每个浏览器中分配__proto__的具体影响是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常具体的用例。这是所有打字稿(对于这种用例我认为它没有影响,但我提到它的情况下)。



我们有我们的主要代码和一个单个web工作者进行后台处理。我们使用Worker.postMessage()来回发送消息。我们总是调用postMessage(myData),其中myData是一个对象。该对象的成员变量是成员变量是对象的对象......它传递了很多对象。



当我们调用postMessage()时,另一方接收提交的对象,但只是数据。方法(即原型)不通过。网络工作者通信序列化数据并重建它,只是数据,在远端。查看交付对象的 proto ,它是一个对象,据我所知,只是一个基本对象。



什么似乎是最明智的方法就是走遍所有设置 proto 的对象()。这样可以避免在复制构造函数中重新创建每个对象(这会花费时间,使内存命中翻倍,并增加垃圾收集器的工作量)。而且这似乎是一件合理的事情,因为我们只是重新应用了发送方的原型。 (在ES6浏览器中,我们将使用setPrototypeOf()。)



我的问题是,以下浏览器的具体点击是什么。它对这些具体的产品有什么影响(我们关心的是最近的版本,因为我们必须有网络工作者):


  • Internet Explorer 10& 11?

  • Chrome 34& 35?

  • Safari 7?



在Firefox的情况下 - 它不喜欢



IE浏览器,Chrome浏览器,苹果浏览器?如果是这样,究竟是什么/如何?

解决方案

答案是 - 在Chrome& Opera在Firefox中非常糟糕,在IE中糟糕透顶。我们对复制构造函数进行了性能测试,并设置了原型。



详情在这里: b
$ b


This is for a very specific use case. And this is all in typescript (which for this use case I think it has no impact but I mention it in case it does).

We have our main code and a single web worker for background processing. We use the Worker.postMessage() to post messages back and forth. We always call postMessage(myData) where myData is an object. That object has member variables that are objects that have member variables that are objects... It's a lot of objects being passed across.

When we call postMessage() what we receive on the other side is the submitted object, but just the data. The methods (ie the prototype) is not passed across. The web worker communication serializes the data and rebuilds it, just the data, on the far side. Looking at the proto for the delivered object, it is an Object as far as I can tell, but just a basic object.

So, what appears to be the most sensible approach is to just walk all the objects setting the proto on them (discussed some here). This avoids re-creating every object again in a copy constructor (which takes time, doubles the memory hit, and increases the work for the garbage collector). And it seems like a reasonable thing to do because we're just reapplying the prototypes it had on the sent side. (And in ES6 browsers we'll use setPrototypeOf().)

My question is, what is the specific hit for the following browsers. What impact does it have for these specific ones (all we care about are the recent versions because we must have web workers):

  • Internet Explorer 10 & 11?
  • Chrome 34 & 35?
  • Safari 7?

And in the case of Firefox - it doesn't like it.

Is it a hit for IE, Chrome, & Safari? And if so, exactly what/how?

解决方案

And the answer is - bad in Chrome & Opera, very bad in Firefox, horribly bad in IE. We did performance testing of copy constructors vs setting the prototype.

Details here:

这篇关于在每个浏览器中分配__proto__的具体影响是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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