当前位置:网站首页>一个方案提升Flutter内存利用率
一个方案提升Flutter内存利用率
2020-11-08 10:29:00 【InfoQ】
背景
我们闲鱼使用的图片方案是自研的外接纹理方案:
- Android侧创建SurfaceTexture,通过FlutterJNI注册到Flutter engine里,最后返回texture id给Flutter应用层,应用层使用Texture Widget和textue id去显示图片纹理。
- 纹理数据则是在Android侧,通过OpenGL将图片纹理写入到SurfaceTexture,然后通过Flutter engine里的共享内存,将纹理数据传入到应用层,最终交给Skia渲染。

这里面存在的问题: Flutter应用层的纹理数据没有缓存,每次都需要重新将Bitmap数据渲染成纹理,再交给Flutter应用层使用。Native图片加载会内存缓存,Flutter自身提供的图片库也存在缓存,这2个缓存相互隔离,占用很大的内存空间。而且Flutter图片缓存基本都是存放的本地资源图,而我们Flutter页面上大部分其实都是网络下载的外接纹理图片,导致缓存资源利用率很低。
分析
针对上述的3个问题,我们先抛开技术实现,假设下要解决这3个问题,最理想的一个解决方案是什么:
- 纹理没有缓存,那我们在应用层增加一个纹理的内存缓存就解决了。
- 当上层的应用层已经缓存纹理,那Native侧的Bitmap的内存缓存也可以被去掉,只保留图片资源的磁盘缓存。
- 整个App的内存缓存,只有纹理缓存,Flutter的ImageCache缓存,为了避免内存资源的浪费,将这2个缓存合成一个
原文链接:【https://www.infoq.cn/article/4t9HrwJFvRh41X2328Gy】。未经作者许可,禁止转载。
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://www.infoq.cn/article/4t9HrwJFvRh41X2328Gy?utm_source=rss&utm_medium=article
边栏推荐
- Distributed consensus mechanism
- Basic concepts of computer network (5) basic principles of local area network
- Insight -- the application of sanet in arbitrary style transfer
- 你搞不懂与别人的差距,永远成不了架构师!月薪15K和月薪65K,你差在那了?
- NOIP 2012 提高组 复赛 第一天 第二题 国王游戏 game 数学推导 AC代码(高精度 低精度 乘 除 比较)+60代码(long long)+20分代码(全排列+深搜dfs)
- Recommend an economic science video, very valuable!
- 虚拟机中安装 macOS 11 big sur
- ArrayList源码分析
- 【总结系列】互联网服务端技术体系:高性能之数据库索引
- OSChina 周日乱弹 —— 之前呢,我一直以为自己是个……
猜你喜欢

ASP.NET A complete solution based on exception handling in MVC

Seven features of Python 3.9

YGC troubleshooting, let me rise again!

Python3.9的7个特性

将“光头”识别为“足球”,AI 摄像头如何犯的错?

Oops, the system is under attack again

Six key points of data science interview

ASP.NET MVC下基于异常处理的完整解决方案

Test requirements for MIC certification of Bluetooth 2.4G products in Japan

ts流中的pcr与pts计算与逆运算
随机推荐
双向LSTM在时间序列异常值检测的应用
攻防世界之web新手题
Flink's sink: a preliminary study
Which is more worth starting with the difference between vivos7e and vivos7
ASP.NET MVC下基于异常处理的完整解决方案
Solve the problem of rabbitmq message loss and repeated consumption
虚拟机中安装 macOS 11 big sur
M 端软件产品设计思虑札记 - 知乎
墨者学院SQL注入解题
python_ scrapy_ Fang Tianxia
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
Bili Bili common API
Python3.9的7个特性
PCIe 枚举过程
FORTRAN 77 reads some data from the file and uses the heron iteration formula to solve the problem
游戏优化性能杂谈(十一) - 知乎
Search and replace of sed
Close to the double 11, he made up for two months and successfully took the offer from a large factory and transferred to Alibaba
Mozi college SQL injection solution
python 循环区分(while循环和for循环)