技术栈中的爱马仕?Facebook发布全新JavaScript引擎:Hermes

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

前言

  • 目前,用户的流畅体验是用户能长期使用某个移动客户端应用App的重要指标之一,因此,移动客户端应用App的性能问题备受关注。
  • 最近,一个崭新的JavaScript引擎面世:Hermes,它是Facebook在Chain React 2019 大会上发布 & 用于在React Native应用提高性能的,今天,我将进行全面介绍。
    示意图

目录

示意图


1. 简介

Facebook在Chain React 2019 大会上发布的一个崭新JavaScript引擎

已开源 & 用于移动端React Native应用的集成

示意图


2. 作用

2.1 背景

  • 用户的流畅体验是用户能长期使用某个移动客户端应用App的重要指标之一,因此,移动客户端应用App的性能问题备受关注
  • 针对React Native应用,流畅度等性能问题一直被人诟病

2.2 问题

Facebook基于多方性能数据分析,发现JavaScript引擎本身就是影响React Native应用启动性能的重要因素

2.3 解决方案

构建一个全新的JavaScript引擎,针对React Native应用,去提高移动客户端应用App的性能

特别注意:Hermes主要面向移动端React Native应用的性能优化,对浏览器 & Node.js 等服务端基础架构并不适用。


3. 性能提升表现

对于React Native应用(基于JavaScript引擎)来说,用户感知最明显的性能体验包括:

  • 应用程序可用的时间(TTI)
  • 安装包下载大小(Android APK 大小)
  • 内存利用率

根据Facebook给出的官方性能优化性能数据如下:
示意图

从上述数据可知,Hermes引擎提升性能较为明显:

  • 在应用程序可用的时间上,Hermes能提升一倍的时间效率
  • 在安装包下载大小下,Hermes能减少50%的大小
  • 在内存利用率上,Hermes能节省30%的内存使用

4. 设计原理

为了提升React Native应用的性能表现,Hermes引擎的设计主要是从是两个方面入手:编译方式 & 垃圾回收策略

4.1 编译方式

a. 字节码预编译

示意图

b. 无JIT编译

示意图

4.2 垃圾回收策略

示意图


5. 使用特点

在实际使用Hermes时,具备3个优点:懒编译、兼容性好 & 调试体验好,具体如下:
示意图

  • 特别注意:在实际使用Hermes时,需对build.gradle文件做更改 & 重新编译
project.ext.react = [
  entryFile: "index.js",
  enableHermes: true
]

6. 总结

  • 本文全面讲解了Facebook在Chain React 2019 大会上发布的一个崭新JavaScript引擎:Hermes
  • 下面我将继续对 Hermes引擎中的知识进行深入讲解 ,感兴趣的同学可以继续关注本人博客Carson_Ho的开发笔记

请帮顶 / 评论点赞!因为你的鼓励是我写作的最大动力!

展开阅读全文

Hermes' Colony

03-01

Hermes, the Greek God of Speed, has created a two-dimensional colony Massilia in space. The colony, consisting of one or more provinces, can be represented by a linear equation in 3-dimensional space. In each province there are 3 or 4 cities, each being on their convex hull. Now, citizens of each province want to create road network connecting cities of their own province. Unfortunately, materials for road construction are not available in the colony, and can only be transported from Earth. Total material required to construct the roads will be proportional to their length. This is why they are interested to build road networks of shortest length connecting different cities of a province. In order to minimize length of each network they are also ready to make junctions away from cities, if so required.nnUnfortunately creatures of the colony are pretty weak in mathematics and algorithms. They have, therefore, decided to take services of homo sapiens of earth, who are believed to be good in mathematics and algorithms. Accordingly the chief of Massilia sent an email to Academy of Computers and Mathematics(ACM) with Head Quarters at Dhaka to solve the problem. ACM has now asked you to help out our friends in Massilia.nnnInputnnThe colony is described by an equation ax+by+cz=d. There are N provinces in the colony. A city in a province can be described by a point in 3-dimension like (x, y, z). All the x, y and z co-ordinates will be within -100.00 and +100.00. The first line of input will contain a, b, c and d. Then the number of provinces (N) in the colony will be given in the second line. The remaining lines will describe each province one by one.nnThe description of a province starts with the number of cities M (3 <= M <= 4) in the province in a line followed by M lines. Each line contains 3 numbers describing respectively the x, y and z co-ordinates of a city in that province.nnnOutputnnYou should print one line for each province in the input data as follows:nnProvince # p : LnnWhere p is the serial number of the province as they appear in the input. 1 <= p <= N, and L is the minimum length of the road network for that province. L should contain two digits after the decimal point and should be exact up to 2 decimal points.nnnSample Inputnn-0.126826 -0.780330 0.612372 3.000000n2n3n11.593475 -0.702393 6.405027n-43.361881 -34.677124 -48.269711n-0.380480 -2.340990 1.837117n4n-15.033179 6.549108 10.130860n-13.950171 -53.592907 -66.282234n49.017246 0.979824 16.299353n46.824024 12.971205 31.125420nnnSample OutputnnProvince # 1 : 86.43nProvince # 2 : 175.15 问答

没有更多推荐了,返回首页