unity webgl内存_了解Unity WebGL中的内存-程序员宅基地

技术标签: python  java  linux  人工智能  大数据  

unity webgl内存

Since we shipped Unity WebGL, we have put a lot of effort into optimizing memory consumption. We’ve also been explaining how memory works in WebGL in the manual and in our talks at Unite Europe 2015 and Unite Boston 2015. However, as this continues to be a hot-topic in our conversation with customers, we realized we should talk more about it. Hopefully this post will answer some of the frequently asked question.

自从我们发布Unity WebGL以来,我们已经在优化内存消耗方面投入了大量精力。 在 手册中 以及在 2015年Unite欧洲2015年 Unite波士顿的 演讲中, 我们还一直在解释内存在WebGL中的工作方式 。 但是,由于这一直是我们与客户交谈中的热门话题,因此我们意识到我们应该对此进行更多讨论。 希望这篇文章能回答一些常见问题。

Unity WebGL与其他平台有何不同? (How is Unity WebGL different from other platforms ?)

Some users are already familiar with platforms where memory is limited. For others, coming from desktop or the WebPlayer, this has never been an issue until now.

一些用户已经熟悉内存受限的平台。 对于其他人,无论是来自台式机还是WebPlayer,到目前为止,这一直不是问题。

Targeting console platforms is relatively easy in this respect, since you know exactly how much memory is available. That allows you to budget your memory and your content is guaranteed to run. On mobile platforms things are a bit more complicated because of the many different devices out there, but at least you can choose the lowest specs and decide to blacklist lower-end devices at the marketplace level.

在这方面,定向控制台平台相对容易,因为您确切知道有多少可用内存。 这样您就可以预算内存,并保证内容可以运行。 在移动平台上,由于 那里存在 许多 不同的设备 ,因此情况 有些复杂 ,但是至少您可以选择最低规格的设备,并决定在市场级别将低端设备列入黑名单。

On the Web, you simply can’t. Ideally, all end-users had 64-bit browsers and tons of memory but that’s far from reality. On top of that, there is no way to know the specs of the hardware your content is running on. You know the OS, Browser and not much more. Lastly, the end-user might be running your WebGL content as well as other web pages. That’s why this is a tough problem.

在网络上,您根本做不到。 理想情况下,所有最终用户都具有64位浏览器和大量内存,但这与实际情况相去甚远。 最重要的是,您无法了解运行内容的硬件规格。 您知道操作系统,浏览器,仅此而已。 最后,最终用户可能正在运行您的WebGL内容以及其他网页。 这就是为什么这是一个棘手的问题。

总览 (Overview)

Here is an overview of memory when running Unity WebGL content in the browser:

这是在浏览器中运行Unity WebGL内容时的内存概述:

image04

This image shows that on top of the Unity Heap, Unity WebGL content will require additional allocations in browser’s memory. That’s really important to understand, so that you can optimize your project and therefore minimize users drop-off rate.

此图显示,在Unity Heap之上,Unity WebGL内容将需要在浏览器的内存中进行其他分配。 理解这一点非常重要,这样您就可以优化您的项目,从而最大程度地减少用户流失率。

As you can see from the image, there are several groups of allocations: DOM, Unity Heap, Asset Data and Code which will be persistent in memory once the web page is loaded. Other ones, like Asset Bundles, WebAudio and Memory FS will vary depending on what’s happening in your content (e.g.: asset bundle download, audio playback, etc.).

从图像中可以看到,有几组分配:DOM,Unity Heap,资产数据和代码,它们将在加载网页后永久保存在内存中。 其他内容(例如资产捆绑包,WebAudio和Memory FS)将根据您内容中发生的情况而有所不同(例如:资产捆绑包下载,音频播放等)。

At loading-time, there are also several browser’s temporary allocations during asm.js parsing and compilation that sometimes cause out-of-memory problems to some users on 32-bit browsers.

在加载时,在asm.js解析和编译期间,还有一些浏览器的临时分配,有时会给32位浏览器上的某些用户造成内存不足的问题。

统一堆 (Unity Heap)

In general, the Unity Heap is the memory containing all Unity-specific game objects, components, textures, shaders, etc.

通常, Unity堆是包含所有特定于Unity的游戏对象,组件,纹理,着色器等的内存。

On WebGL, the size of the Unity heap needs to be known in advance so that the browser can allocate space for it and once allocated, the buffer cannot shrink or grow.

在WebGL上,需要预先知道Unity堆的大小,以便浏览器可以为其分配空间,并且一旦分配,缓冲区就不会缩小或增长。

The code responsible for allocating the Unity Heap is the following:

负责分配Unity堆的代码如下:

1

buffer = new ArrayBuffer(TOTAL_MEMORY);

1

buffer = new ArrayBuffer ( TOTAL_MEMORY ) ;

This code can be found in the generated build.js, and will be executed by the browser’s JS VM.

该代码可以在生成的build.js中找到,并将由浏览器的JS VM执行。

TOTAL_MEMORY is defined by WebGL Memory Size in the Player Settings. The default value is 256mb, but that’s just an arbitrary value we chose. In fact an empty project works with just 16mb.

TOTAL_MEMORY由“播放器设置”中的WebGL内存大小定义。 默认值为256mb,但这只是我们选择的任意值。 实际上,一个空项目仅占用16mb。

However, real-world content will likely need more, something like 256 or 386mb in most cases. Keep in mind that the more memory is needed, the fewer end-users will be able to run it.

但是,现实世界中的内容可能需要更多,在大多数情况下约为256mb或386mb。 请记住,需要的内存越多,最终用户运行它的数量就越少。

源代码/编译后的代码存储器 (Source/Compiled Code memory)

Before the code can be executed, it needs to be:

在执行代码之前,它需要:

  1. downloaded.

    已下载。

  2. copied into a text blob.

    复制到文本Blob中。

  3. compiled.

    编译。

Take into consideration that, each of these steps will require a chunk of memory:

考虑到这些步骤中的每一个都将需要一块内存:

  • The size of the downloaded buffer and the source code are both the size of the uncompressed js generated by Unity. To estimate how much memory will be needed for them:

    下载缓冲区的大小和源代码都是Unity生成的未压缩js的大小。 估计它们将需要多少内存:

    • make a release build

      发布版本

    • rename jsgz and datagz to *.gz and unpack them with a compression tool

      将jsgz和datagz重命名为* .gz并使用压缩工具将其解压缩

    • their uncompressed size will also be their size in browser’s memory.

      它们的未压缩大小也将是它们在浏览器内存中的大小。

    The size of the downloaded buffer and the source code are both the size of the uncompressed js generated by Unity. To estimate how much memory will be needed for them:

    下载缓冲区的大小和源代码都是Unity生成的未压缩js的大小。 估计它们将需要多少内存:

  • The size of the compiled code depends on the browser.

    编译代码的大小取决于浏览器。

An easy optimization is to enable Strip Engine Code so that your build will not include native engine code that you don’t need (e.g.: 2d physics module will be stripped if you don’t need it). Note: Note: Managed code is always stripped.

一个简单的优化就是启用“剥离引擎代码”,以便您的构建中不包含不需要的本机引擎代码(例如:如果不需要,则将剥离2d物理模块)。 注意:注意:托管代码始终被剥离。

Keep in mind that Exceptions support and third party plugins are going to contribute to your code size. Having said that, we have seen users that need to ship their titles with null checks and array bound

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/culiao6493/article/details/108642347

智能推荐

Android Studio导入github下载的工程_导入别人的安卓项目没有自动下载-程序员宅基地

文章浏览阅读1.7k次。现在从github上面现在的项目大部分都是Android Studio工程,那么问题来了,从github上面down一个工程下来,怎么导入android studio呢?对刚从eclipse转Android Studio的童鞋来说,可能会遇到各种问题。下面方法可以简单快速的将github上的项目导入android studio并运行。_导入别人的安卓项目没有自动下载

html按钮按下效果_您应该在网站中尝试的8种惊人的HTML按钮悬停效果,让您的网站令人难忘...-程序员宅基地

文章浏览阅读403次。HTML按钮悬停效果简介按钮是每个页面,Web应用程序或移动应用程序中经常使用的基本HTML元素。HTML按钮是布局中非常重要的元素,因为在很多情况下,它是用户在呼吁采取行动并说服单击时必须注意到的元素。前端开发人员和设计人员经常尝试以任何不错的方式突出显示按钮,尤其是当用户与它们交互时,例如悬停或聚焦时。因此,今天我决定向您展示8种出色的HTML按钮悬停效果,您可以在项目中使用它们,并使用户和客..._按钮的悬停和按下效果设计

VMware Pro16 安装MacOS 11/12教程_vm16pro 安装 macos11-程序员宅基地

文章浏览阅读6.8k次,点赞2次,收藏27次。本文引用了诸多教程, 如有侵犯, 请联系以删除写作日期: 2022年2月22日1. 原料准备VMware Pro实测VMware Pro16.0.0最高只有MacOS11.1, VMware Pro16.2.2有MacOS12和MacOS13, 需要配合unlocker使用VMware Pro的安装和NAT网络配置请自行百度实测在VMware Pro16.0.0上选择MacOS11.1可以按照12.2unlocker用于给VMware Pro添加MacOS的选项unlocker下载地址._vm16pro 安装 macos11

Java原来可以这么玩!CV视频合成处理,视频前后拼接,画面合并_java怎么做视频合成-程序员宅基地

文章浏览阅读1.3k次,点赞26次,收藏19次。本章内容教会你如何用java代码实现 两个视频的画面合并 或者前后拼接。原理是使用了javacv开源jar包,代码经过反复修改,已经实现我能想到的最优最快的实现,如果你有更好更快的实现,欢迎评论区留言!!!先展示一下效果吧!!!两个视频前后拼接两个视频画面合并。_java怎么做视频合成

Windows iPhone VMware [转]-程序员宅基地

文章浏览阅读256次。 本文在Windows Xp + VMware Workstation 7.0 + MAC OS X Snow Leopard 10.6 环境下安装iPhone SDK 3.1.2成功! -------------------------------------- 安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB以上内存的PC。 本人采用笔记本:DELL D630 4G内存 注意:..._iphone vmware

【Unity3D入门教程】Unity3D界面介绍及游戏对象基本操作_u3d2017页面操作-程序员宅基地

文章浏览阅读4w次,点赞30次,收藏95次。本文介绍了Unity3D界面及游戏对象基本操作。_u3d2017页面操作

随便推点

Spring Boot中,jar包、war包的区别_springboot引入外部jar包的区别-程序员宅基地

文章浏览阅读715次。参考链接:https://www.cnblogs.com/cag2050/p/7833541.htmlSpringBoot打包的jar包和传统jar是有区别的这个JAR包与传统JAR包的不同之处在于里面有一个名为lib的目录,在这个目录中包含了这个简单应用所依赖的其他JAR包,其中也包含内置的嵌 入式Tomcat,正是使用它,才能发布服务和访问Web资源。除了我们编写的源码所编译形成..._springboot引入外部jar包的区别

miui v5 android版本,速度明显提升 小米2S刷安卓4.4版MIUI V5-程序员宅基地

文章浏览阅读2.3k次。1小米2S刷安卓4.4版MIUI V5小米官方已经正式开始了基于Android4.4的MIUIV5内测工作,按照此前的说法目前小米所有的机型的ROM均会升级到Android4.4,第一批机型也选择了搭载骁龙800处理器的联通/电信版小米3,目测其他小米手机想要用上最新内核的MIUIV5还需要一段时间的等待。不过近日论坛上放出了适配小米2/2S的安装包,据悉是由小米员工个人制作,让这款退役..._小米2s miuiv5 4.4

[Android实例] Sensor传感器源码的阅读与应用开发简单实例_安卓光感apk源码-程序员宅基地

文章浏览阅读746次。转自http://www.apkbus.com/android-804-1-1.htmlAndroid系统支持多种传感器。应用到各个层次,有的传感器已经在Android的框架中使用,大多数传感器由应用程序中来使用。一.Android中支持的传感器类型: 2011-4-25 08:22 上传下载附件(1_安卓光感apk源码

使用Pycharm给Python程序传递参数_pycharm配置pytest运行程序 传递-m参数-程序员宅基地

文章浏览阅读8.9w次,点赞36次,收藏86次。Pycharm 的设置--参数设置程序运行时,如果需要输入参数,如下图中代码:生成exe后,程序运行时格式为:这种情况在调试程序时,如果只是在Pycharm环境中简单执行“Run”菜单下的“Run”命令,会出现以下错误,提示需要输入参数。为了解决这个问题,我们需要点击“Run”菜单下的"Edit Configurations..."命令_pycharm配置pytest运行程序 传递-m参数

解决AttributeError AttributeError: 'NoneType' object has no attribute 'filename'_inmemoryuploadedfile' object has no attribute 'sav-程序员宅基地

文章浏览阅读1w次。原因忘记上传文件 表单需要加属性enctype="multipart/form-data"否则报错!AttributeError AttributeError: 'NoneType' object has no attribute 'filename'enctype="multipart/form-data是设置表单的MIME编码。默认情况,这个编码格式是applicatio..._inmemoryuploadedfile' object has no attribute 'save

小程序转义html标签,wxDiscode-微信小程序特殊字符转义符转化工具类-程序员宅基地

文章浏览阅读724次。问题在大部分html或者其它富文本在保存到后台中,为了安全起见需要将一些特殊字符进行转义但是,请求回来的信息中包涵着这些转义过后的字符,而微信小程序是不能够直接进行反转义成为html特殊字符,所以需要将字符串特殊字符替换后才能恢复作用用于转义html中的特殊字符解析类型HTML 支持的数学符号HTML 支持的希腊字母HTML 支持的其他实体代码很简单,复制粘贴太难,所以提供给大家以便使用,欢迎补充..._微信小程序开发复制特殊字符

推荐文章

热门文章

相关标签