pixi与lottie-web的benchmark测试

 生产版本

 

"dependencies" : {
     "lottie-web" "^5.5.7" ,
     "pixi-spine" "^1.5.23" ,
     "pixi.js" "^4.8.8"
}

 

讲座项目对资源作对比

ps:测试网络环境:fast 3gjava

gzip大小
打包使用的资源
资源数
加载方式
绘制

FPweb

onload
pixi&pixi-spine 34.08+77.04 = 121.12kb 147kb 4

xhrjson

webGL/canvas 1409ms 15147ms
lottie-web
61.5kb 291 +41 = 332kb 30 非xhr canvas/svg 1416ms 13978ms


pixi

      Pixi 是一个至关完善的基于 WebGL 的 2D 渲染层,对不支持 WebGL 浏览器可采用 Canvas 垫背(2D WebGL renderer with canvas fallback)。canvas

       设计理念 Pixi.js的设计理念不少程度来源于它的定位,只作渲染器,要把渲染功能作到最强。而这样的定位,则会让Pixi.js成为其余引擎的渲染内核。Pixi.js中的显示架构彻底参考Flash设计,全部显示对象组合为一个树状数据结构,但内部已针对WebGL渲染方式进行过优化,上层使用起来和Flash并没有太大差异。api

业界使用

Phaser并无本身的渲染内核,而是直接引用了Pixi.js。浏览器

 

渲染压力测试

测试内容为同屏渲染对象数量相同的状况下进行帧频数据对比,为了保证测试的公平性,我使用同一台电脑,相同版本的Chrome浏览器进行测试,游戏场景尺寸均为800*600,显示的图片也为同一张。网络

100、300、500、600、1000、2000、3000个显示对象渲染。数据结构

 电脑配置架构

 

库/显示对象数量
100
300
500
600
1000
2000
2500
3000
pixi 60 60 60 59.9 59 35 32 28
lottie-web(canvas) 55 40 36 24 10 - - -
lottie-web(svg) 40 25 10 - - - - -

结论

对与显示对象小于600的,pixi与lottie在可接受范围内,对于大于600个渲染对象的项目,须要使用pixiapp

对于小于100个显示对象的,三种渲染方式均可行,但pixi要优于lottie-web

 

 测试代码

require('pixi.js')
 
var renderer = PIXI.autoDetectRenderer(800, 600, { backgroundColor: 0x1099bb });
 
document.body.appendChild(renderer.view);
 
var stage = new PIXI.Container();
 
var texture = PIXI.Texture.fromImage('./lottie-assets/images/img_0.png');
 
var tnum = 1000;
 
console.log("render Object Number:", tnum);
 
var bunnys = [];
 
for (var i = 0; i < tnum; i++) {
 
  var bunny = new PIXI.Sprite(texture);
 
  bunny.position.x = Math.random() * 800;
 
  bunny.position.y = Math.random() * 600;
 
  stage.addChild(bunny);
 
  bunnys.push(bunny);
 
}
 
animate();
 
function animate() {
 
  requestAnimationFrame(animate);
 
  for (var i = 0; i < tnum; i++) {
 
    // bunnys[i].rotation += 0.1;
 
  }
  renderer.render(stage);
}

  

import lottie from 'lottie-web'
 
animate();
 
function animate() {
 
  requestAnimationFrame(animate);
  lottie.loadAnimation({
    container: document.body, // the dom element that will contain the animation
    renderer: 'canvas',
    loop: false,
    autoplay: true,
    path: './lottie-assets/data1.json' // the path to the animation json
  });
  var timer = null;
  clearTimeout(timer)
  timer = setTimeout(function () {
    lottie.destroy();
  },2000)
}
相关文章
相关标签/搜索