使用场景:稳定的视图(layer)被反复使用或进行动画;

本质:牺牲内存解放cpu;

反例:牺牲内存牺牲cpu。

单次使用或者视图有变动,shouldRasterize不会有任何用途,反而会牺牲内存。

shouldRasterize会触发离屏渲染,所以会降低一次性渲染的效率。

Bottom line if you have a complex view (i.e. relatively expensive to re-render) that you are animating, but for which the animated view is not itself changing, rasterizing the layer can improve the performance by not re-rendering the layer all the time. But it does this at the cost of memory (saving a rasterized image in memory).

But, if you animate a change within the layer, the shouldRasterize can adversely affect performance (because it's going to re-rasterize the layer for each frame of the animation).

Generally, if animating a complex set of layers that, themselves, are not changing, then you can set shouldRasterize to YES, do the animation, and then turn off shouldRasterize.

https://stackoverflow.com/questions/19405741/when-should-i-set-layer-shouldrasterize-to-yes

  Would setting shouldRasterize to YES improve animation performance though? – Senior Sep 12 '12 at 15:47

  • It depends on how you are performing your animations. If you are using the animation methods on UIView, one of the animation options is to allow rendered content of the views its animating. This is off by default, which means the animation will take a snapshot of the view and animate that. So in that case rendering would not really be affected. If you're using CAAnimations, you will get a performance increase by setting shouldRasterize, because the animation will only animated the rasterized layer, and not ask it to draw each frame of the animation loop. – gdavis Sep 12 '12 at 17:58 
     
    https://stackoverflow.com/questions/12338553/does-calayer-shouldrasterize-propagate-to-all-sublayers?r=SearchResults
当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源。

作者:Heikki_
链接:https://www.jianshu.com/p/d56ba5b7bc27
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

而光栅化会导致离屏渲染,影响图像性能,那么光栅化是否有助于优化性能,就取决于光栅化创建的位图缓存是否被有效复用,而减少渲染的频度。可以使用Instruments进行检测:

当你使用光栅化时,你可以开启“Color Hits Green and Misses Red”来检查该场景下光栅化操作是否是一个好的选择。
如果光栅化的图层是绿色,就表示这些缓存被复用;如果是红色就表示缓存会被重复创建,这就表示该处存在性能问题了。

作者:路漫漫其修远兮Wzt
链接:https://www.jianshu.com/p/ce73e3836730
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

shouldRasterize 光栅化、(缓存)复用、内存、内容稳定的更多相关文章

  1. DirectX11 With Windows SDK--11 混合状态与光栅化状态

    前言 虽然这一部分的内容主要偏向于混合(Blending),但这里还需提及一下,关于渲染管线可以绑定的状态主要有如下四种: 光栅化状态(光栅化阶段) 采样器状态(像素着色阶段) 混合状态(输出合并阶段 ...

  2. Linux 释放cache化缓存

    Linux 释放cache化缓存 free -g查看空余内存以及已使用内存 原文  https://blog.csdn.net/tomspcc/article/details/78131468 机械硬 ...

  3. ASP.NET Core 中的SEO优化(1):中间件实现服务端静态化缓存

    分享 最近在公司成功落地了一个用ASP.NET Core 开发前台的CMS项目,虽然对于表层的开发是兼容MVC5的,但是作为爱好者当然要用尽量多的ASP.NET Core新功能了. 背景 在项目开发的 ...

  4. DirectX11 With Windows SDK--07 添加光照与常用几何模型、光栅化状态

    原文:DirectX11 With Windows SDK--07 添加光照与常用几何模型.光栅化状态 前言 对于3D游戏来说,合理的光照可以让游戏显得更加真实.接下来会介绍光照的各种分量,以及常见的 ...

  5. opengles2.0之图元装配和光栅化

    光栅化的过程就是把三维世界中的物体转换成屏幕上像素的过程. glGetfloatv();    --------v表示的是数组 gles2.0里面有两种绘图命令.glDrawArrays和glDraw ...

  6. 【Hadoop学习】HDFS中的集中化缓存管理

    Hadoop版本:2.6.0 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4146398.html 概述 ...

  7. 13.缓存、三级缓存、内存溢出、AsyncTask

    SharePreference工具类 /** * SharePreference封装 * */ public class PrefUtils { public static final String ...

  8. Django中的缓存(内存,文件,redis)

    一.Django中的缓存的几种方法 1)单个视图缓存.时间测试 import time from django.views.decorators.cache import cache_page @ca ...

  9. GPU大百科全书 第二章 凝固生命的光栅化

    光栅化——死神来了……   前言:在上一期的GPU大百科全书里,我们目睹了可爱的香草从抽象世界走向现实,从方程还原成实体的全过程.可以说香草活了,因为几何单元,我们赋予了她完整的灵魂. 如果你正在为G ...

随机推荐

  1. [转]Grunt 新手一日入门

    本文转自:http://yujiangshui.com/grunt-basic-tutorial/ 当时学习 Grunt 的时候,真是很头疼.分了两个时间段,学习了两次才硬啃下来,之后才能用在项目中. ...

  2. ssh 远程拷贝文件到本地

     scp userA@192.168.0.205:/home/xinshang-toolkit/wwwroot/macheng/tianxiaohuanew-mc.dsceshi.cn/public/ ...

  3. Xss和Csrf介绍

    Xss和Csrf介绍 Xss Xss(跨站脚本攻击),全称Cross Site Scripting,恶意攻击者向web页面中植入恶意js代码,当用户浏览到该页时,植入的代码被执行,达到恶意攻击用户的目 ...

  4. android FrameLayout

    FrameLayout:帧布局,可以显示图片的动画效果 前景图像: 永远处于帧布局最顶的,直接面对用户的图像,,就是不会被覆盖的图片 常用属性: android:foreground:设置该帧布局容器 ...

  5. Vue学习笔记:编译过程

    碰到是否有template选项时,会询问是否要对template进行编译: 在template编译(渲染成UI)有一个过程.模板通过编译生成AST,再由AST生成Vue的渲染函数,渲染函数结合数据生成 ...

  6. JAVA注释方式

    1.单行(single-line)注释    //…… 2.块(block)注释                /*……*/ 3.文档注释                      /**……*/

  7. java自学-编程入门

    java语言写的代码需要先编译为可执行文件,才能被jvm执行.在下载的jdk安装目录下的bin目录,有两个可执行程序java.exe和javac.exe,javac就是用来编译的,java是执行编译后 ...

  8. csu 1356 Catch bfs(vector)

    1356: Catch Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 96  Solved: 40[Submit][Status][Web Board] ...

  9. jQuery bind()与delegate()的区别

    笔试题: bind()与delegate()的区别主要有三点: 1 绑定目标 .bind直接绑在目标元素上 .delegate绑在父元素上 2  监听个数 .bind监听个数多——每个目标元素都需要添 ...

  10. PHP 如何向关联数组指定的 Key 之前插入元素

    PHP 关联数组可以通过三种方式插入新元素: $array[$insert_key] = $insert_value; $array = array_merge($array, $insert_arr ...