打破双亲委派么,怎么打破

Lancelot was always looking for bigger and

兰斯洛特一直在寻找更大的

大标题 (bigger titles)

to work on. And so he worked hard to get his big chance in the games industry.

继续努力。 因此,他努力工作,以获得在游戏行业的巨大机会。

It was not easy, that he knew.

他知道这并不容易。

These spots in the game industry were and still are reserved for a small minority of game programmers. And he wasn't sure he'd be up to the standards, anyway.

游戏行业中的这些位置过去是,现在仍然是为少数游戏程序员保留的。 而且他不确定自己是否会达到标准。

But he persisted and continued to sharpen his programming skills.

但是他坚持并继续提高他的编程技巧。

Lancelot started working on small games. Maybe at some point, he would get the big chance he was looking for, he thought.

兰斯洛特开始从事小型游戏。 他想,也许在某个时候,他会得到他寻找的巨大机会。

Years passed till he got the opportunity he was waiting for. He was asked to port a big VR game to a mobile platform. As excited as Lancelot was, he couldn't stop wondering if he was

几年过去了,直到他获得了等待的机会。 他被要求将大型VR游戏移植到移动平台上。 像兰斯洛特一样兴奋,他不停地想知道自己是否

够好了 (good enough)

for the task. It was daunting but he accepted the challenge. He knew that he could only grow out of that.

为任务。 这令人生畏,但他接受了挑战。 他知道他只能从中成长。

Lancelot's biggest concern was the need to massively improve the performance of the game. It was a double challenge, in fact. He had to

兰斯洛特最大的担忧是需要大幅提高游戏性能。 实际上,这是双重挑战。 他必须

将性能提高20% (improve performance by 20%)

for a considerably

相当大的

功能较弱的平台 (less powerful platform)

.

After months of non-stop work, he finally managed to optimize the game enough to have a rock-solid performance baseline.

经过几个月的不间断工作,他终于设法对游戏进行了足够的优化,以达到坚实的性能基准。

However, an unexpected issue was just around the corner…

然而,一个意想不到的问题迫在眉睫……

The unity profiler revealed him a considerable frame-rate drop every few seconds. And that worried him because that wouldn't allow him to ship the game. The game release was in jeopardy. That made him utterly uncomfortable.

统一的分析器向他显示,每隔几秒钟便有相当大的帧速率下降。 这让他感到担心,因为那将不允许他发布游戏。 游戏发行受到威胁。 那使他完全不舒服。

Based on his previous experience, Lancelot quickly suspected of the

根据他以前的经验,兰斯洛特很快就怀疑

垃圾收集器 (garbage collector)

. After all, he knew that allocating temporary memory in the game too often could cause these performance spikes. Just like the trash can in everyone's kitchen, you know it's time to clean it when it reaches 80% of its capacity.

。 毕竟,他知道在游戏中过多分配临时内存可能会导致这些性能峰值。 就像每个人厨房中的垃圾桶一样,当垃圾量达到其容量的80%时,就该清理它了。

And so he spent days fighting the bothersome memory allocations. He performed all types of optimizations he could think of. Object pools, data caching, data structure optimizations…

因此,他花了几天的时间来解决烦人的内存分配问题。 他执行了他能想到的所有类型的优化。 对象池,数据缓存,数据结构优化…

Spending these days optimizing got him a bit ahead in the performance journey. Lancelot was proud of his work, but his concerns only grew when he saw the garbage collector still running every 15 seconds.

这些天的花费优化使他在性能旅程中遥遥领先。 兰斯洛特为自己的工作感到骄傲,但直到他看到垃圾收集器每15秒仍在运行时,他的担忧才会增加。

Playing the game in VR with these performance drops would somehow make people look pale.

在这些性能下降的情况下在VR中玩游戏会使人显得苍白。

«How could that be happening?» he wondered.

«怎么会这样?» 他想知道。

With more patience and digging, Lancelot discovered a second source of memory allocations he didn't see before. Those happened in a

经过更多的耐心和挖掘,Lancelot发现了他之前从未见过的第二个内存分配来源。 那些发生在

第三方图书馆 (3rd party library)

.

He had a look and soon realized he was in the worst position ever: that library was closed source. Not only that, he also tried using Unity's

他看了一下,很快就意识到自己处于有史以来最糟糕的位置:该库是封闭源代码。 不仅如此,他还尝试使用Unity的

增量垃圾收集器 (incremental garbage collector)

but he couldn't afford to pay its performance price.

但他负担不起性能价格。

Lancelot was running out of options.

Lancelot的选项已用完。

He felt desperate but managed to keep calm. He's been in worse situations after all.

他感到绝望,但设法保持镇定。 毕竟他一直处在更糟糕的情况下。

He could

他可以

反向工程 (reverse engineer)

the library and do the memory allocation optimizations himself. The problem was that the license disallowed such things. And he was too young to go to jail.

库并自己进行内存分配优化。 问题是许可证不允许这种事情。 而且他还太年轻,无法入狱。

The second option he considered was to

他考虑的第二个选择是

预分配 (pre-allocate)

a lot of memory on the heap. He knew that unity triggered the garbage collection process when the heap usage reached a certain percentage. So increasing the heap should give him more time between garbage collections.

堆上有很多内存。 他知道,当堆使用率达到一定百分比时,团结会触发垃圾回收过程。 因此增加堆应该给他更多的时间来进行垃圾回收。

Sadly, that was still not enough.

可悲的是,这还不够。

It slowly felt as if he had no control over the situation. It was tough, but again, he

慢慢地,他觉得自己无法控制局势。 很难,但再次,他

坚持 (persisted)

.

So Lancelot came up with a

所以兰斯洛特想出了一个

疯狂的主意 (crazy idea)

. What if he disabled the garbage collection entirely? Was that even possible? He felt in his bones how risky such an idea was. He didn't want to add the possibility for the game to crash at unpredictable points. Last time he checked, that was no fun for the players. Maybe times did change, but better safe than sorry.

。 如果他完全禁用垃圾收集怎么办? 那有可能吗? 他觉得自己的想法多么危险。 他不想增加游戏崩溃的可能性。 上一次他检查时,对于球员来说这并不有趣。 也许时代确实发生了变化,但安全胜过遗憾。

On top of that, he worried about delaying the release of the game. He didn't want his players to miss this title for Christmas. He remembered how much fun he had playing EverQuest during these holidays. He wouldn't take that away from the players.

最重要的是,他担心推迟游戏的发布。 他不想让他的球员在圣诞节错过这个冠军。 他记得在这些假期里玩EverQuest有多少乐​​趣。 他不会从球员身上夺走这些。

Reached this point, he had no other choice than to disable the garbage collector.

达到这一点,他除了禁用垃圾收集器外别无选择。

He got into research mode and found that he could indeed

他进入研究模式,发现他确实可以

手动禁用垃圾收集 (manually disable the garbage collection)

. He ran dozens of experiments to see how long the game would hold without running out of memory. He did all sorts of tests to stress the system. Clicking everywhere, walking and jumping around, switching between different applications.

。 他进行了数十次实验,以观察游戏在不耗尽内存的情况下能保持多长时间。 他做了各种各样的测试来强调系统。 单击各处,四处走动,在不同的应用程序之间切换。

号码 (Numbers )

started arriving in his spreadsheet: 25 minutes, 28 minutes, 30 minutes… He also noted how the heap usage increased over time to be certain he'd never exceed a safe budget.

开始进入他的电子表格:25分钟,28分钟,30分钟……他还指出了堆使用量随时间增加的方式,以确保他永远不会超出安全预算。

With those numbers, Lancelot established a generous

有了这些数字,兰斯洛特建立了一个慷慨的

安全裕度 (safe margin)

and prepared a

并准备了

原型 (prototype)

. He would run the garbage collection manually during loading screens and every few minutes.

。 他将在加载屏幕期间以及每隔几分钟手动运行垃圾收集。

He had hope again.

他又有了希望。

He politely asked QA to go through the game dozens of times.

他彬彬有礼地要求质量检查人员进行数十遍游戏。

Memory was always within the budget. No crashes. No side effects.

内存总是在预算之内。 没有崩溃。 没有副作用。

This long journey brought him to the point where he was able to

漫长的旅程将他带到了他能够

船 (ship )

the game.

游戏。

And guess what? Hundreds of players are now enjoying it over the Christmas period.

你猜怎么着? 在圣诞节期间,数百名玩家现在正在享受它。

In the beginning, he was not comfortable with this solution. It was a risky move and he knew it. But he managed to pull it off.

一开始,他对这种解决方案不满意。 这是一个冒险的举动,他知道。 但是他设法做到了。

Lancelot learned to be comfortable with the

兰斯洛特学会了适应

不舒服 (uncomfortable)

. He learned to be more

。 他学会了变得更多

务实 (pragmatic)

. Because there are times when a programmer has to be.

。 因为有时候必须要有程序员。

Does anything of the story ring a bell? If so, your intuition is probably right.

故事有什么响吗? 如果是这样,您的直觉可能是正确的。

That programmer was me.

那个程序员就是我。

For the times you need it, this is how you can manage the garbage collector:

在您需要的时候,这是管理垃圾收集器的方式:

That code snippet shows you how to disable automatic garbage collections. It runs the GC process manually every minute and possibly during screen transitions (fade to black).

该代码段向您展示了如何禁用自动垃圾收集。 它每分钟以及可能在屏幕转换(淡入黑色)期间手动运行GC过程。

Be aware of its possible side effects:

请注意其可能的副作用:

  • 崩溃 (Crashes)

    : if you don't play safe enough you'll run out of memory. Worse, the OS might kill your game when you switch between applications

    :如果您的游戏不够安全,则会耗尽内存。 更糟糕的是,当您在应用程序之间切换时,操作系统可能会杀死您的游戏

  • 更长的垃圾收集时间 (Longer garbage collection times)

    : increasing the heap will make future garbage collections slower

    :增加堆将使以后的垃圾收集变慢

If you need to produce generous amounts of garbage, here's a straightforward method that'll just work:

如果您需要产生大量的垃圾,这是一个可以使用的简单方法:

public class GenerousGarbageCreator : MonoBehaviour
{[SerializeField] private int garbageCreationRate = 1024;private static int[] _garbage;void Update(){_garbage = new int[garbageCreationRate];}
}

This is what you'll be getting in the profiler:

这是您将在探查器中获得的内容:

Unity Garbage Collection: Time-Based Manual TriggerUnity垃圾收集:基于时间的手动触发器

There you see an increasing memory usage. The growing heap usage is highlighted as «mono». Luckily for us, we're running the manual garbage collector every 3 seconds.

在那里,您看到内存使用率在增加。 不断增加的堆使用量突出显示为“ mono”。 对我们来说幸运的是,我们每3秒运行一次手动垃圾收集器。

You can clearly see this garbage generation-clearance cycle in the profiler graph. For those game developers who studied physics, you might recognize it as a sawtooth wave shape.

您可以在探查器图中清楚地看到此垃圾生成清除周期。 对于那些研究物理的游戏开发人员,您可能会认为它是锯齿波形。

If you want the source code of this project, you know where to find it (spoiler: here).

如果您想要该项目的源代码,则知道在哪里可以找到它(扰流器:此处)。

For more general memory optimizations, you might be interested in Unity Addressables. With addressables you get to reduce your total memory usage so you can trigger garbage collections less frequently. In turn, this will reduce the performance spikes your players will experience.

有关更常规的内存优化,您可能对Unity可寻址对象感兴趣。 使用可寻址对象,您可以减少总内存使用量,从而可以更不频繁地触发垃圾回收。 反过来,这将减少您的播放器会遇到的性能峰值。

I'm looking forward to working with you all in 2020.

我期待在2020年与大家一起工作。

Ruben

鲁本

翻译自: https://habr.com/en/post/484710/

打破双亲委派么,怎么打破

打破双亲委派么,怎么打破_打破统一垃圾收集规则相关推荐

  1. 双亲委派模型为什么要打破双亲委派模型

    目录 一:什么是双亲委派模型 二:什么情况下要打破双亲委派模型 三:如何打破 一:什么是双亲委派模型 Java 虚拟机对 class 文件采用的是按需加载的方式(也可以称之为懒加载),也就是说当 需要 ...

  2. 【04-JVM面试专题-什么是双亲委派机制(父类委托机制)?如何打破双亲委派机制?双亲委派机制的优缺点?什么是沙箱安全机制呢?】

    什么是双亲委派机制?如何打破双亲委派机制? JVM的双亲委派机制知道吗?怎么打破它呢?你看看自己掌握的怎么样呢? 什么是双亲委派机制?(父类委托机制) 检查某个类是否已经加载 自底向上,从Custom ...

  3. 打破双亲委派么,怎么打破_打破了vs你错了

    打破双亲委派么,怎么打破 为微服务构建REST API时,需要做出一些关于响应的设计决策. 某些响应显然是微服务周围协议的产物-例如3xx代码之类的东西都与重定向和路由有关. 通常,您将尝试获取正确的 ...

  4. 打破双亲委派么,怎么打破_质量保证被打破。 这就是我们如何使其像其他所有东西一样敏捷。...

    打破双亲委派么,怎么打破 by Derwin 由Derwin 质量保证被打破. 这就是我们如何使其像其他所有东西一样敏捷. (Quality Assurance is broken. Here's h ...

  5. 打破双亲委派么,怎么打破_打破它。 然后告诉我们您是如何打破它的。

    打破双亲委派么,怎么打破 The latest version of freeCodeCamp's learning platform is now live on freeCodeCamp.rock ...

  6. 打破双亲委派么,怎么打破_快速行动,不要打破事物

    打破双亲委派么,怎么打破 by Guido Schmitz 由Guido Schmitz 快速行动,不要打破事物 (Move Fast and Don't Break Things) 测试驱动开发简介 ...

  7. 自定义类加载器以及打破双亲委派

    0x01 自定义类加载器 自定义类加载器加载一个类需要:继承ClassLoader,重写findClass,如果不想打破双亲委派模型,那么只需要重写findClass:如果想打破双亲委派模型,那么就重 ...

  8. java 打破双亲委派_JVM - 打破双亲委派机制(模拟热加载)

    如果需要热部署,使用"双亲委派"是不行的,如何打破"双亲委派"呢~ 一. 源代码 "双亲委派"源代码如下(ClassLoader.java) ...

  9. 类加载器的双亲委派及打破双亲委派

    一般的场景中使用Java默认的类加载器即可,但有时为了达到某种目的又不得不实现自己的类加载器,例如为了达到类库的互相隔离,例如为了达到热部署重加载功能.这时就需要自己定义类加载器,每个类加载器加载各自 ...

  10. 如何打破双亲委派机制

    双亲委派机制 第一次知道何为打破双亲委派机制是通过阅读周志明的<深入理解Java虚拟机>,我们知道双亲委派机制是指当一个类加载器收到一个类加载请求时,该类加载器首先会把请求委派给父类加载器 ...

最新文章

  1. Silverlight入门系列]使用MVVM模式(1):MVVM核心概念
  2. pandas库简单入门
  3. 处理2D图像和纹理——显示文字
  4. Eclipse is running in a JRE, but a JDK is required错误的解决
  5. 一体化系统中心服务器,数据中心一体化:监测与控制
  6. 使用ANT打包Android应用
  7. keras系列︱Application中五款已训练模型、VGG16框架(Sequential式、Model式)解读(二)...
  8. 云图说|初识云数据库GaussDB(for Redis)
  9. 【Oracle】开、关、删归档日志(archivelog)
  10. 学linux哪个版本号,初学Linux哪个发行版本好?这些更合适!
  11. 短视频服务大PK,阿里云、腾讯云、又拍云、七牛云、金山云5强横向对比
  12. CKS学习笔记-Sysdig
  13. 弗洛伊德算法原理解释(数学证明)
  14. 8分之七怎么用计算机,如何用八屏电脑看盘
  15. P4578 [FJOI2018]所罗门王的宝藏
  16. 多制式射频信号发生器 信号源
  17. curl: (6) Could not resolve host: www.huobi.me; Unknown error
  18. 互联网企业安全建设之路:互联网企业为什么要做安全?
  19. 移动端APM网络监控与优化实践
  20. 黑苹果oc清除nvram_自己组装一台“iMac”是什么体验(下):AMD 平台也能吃上黑苹果...

热门文章

  1. TMS VCL UI包功能和特点
  2. 通讯录管理系统(C++)
  3. 科比:你知道洛杉矶每天早上四点钟是什么样子吗?
  4. 5款十分小众,却又非常好用的良心软件
  5. python除法程序_Python中的除法
  6. bcm43142 linux 驱动下载,CentosRedhat下bcm43142博通无线网卡linux驱动之二
  7. MIPS中的异常处理和系统调用
  8. linux team 模式,linux 聚合口 team libteam 简介
  9. 华南理工计算机就业棒棒,为梦想、为公益,华南理工大学学子为爱发声
  10. 巨潮网怎么下载年报_如何下载上市公司的年度报告