当前位置:网站首页>一个方案提升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
边栏推荐
- How did Julia become popular?
- 渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
- Rust:命令行参数与环境变量操作
- Close to the double 11, he made up for two months and successfully took the offer from a large factory and transferred to Alibaba
- YGC问题排查,又让我涨姿势了!
- [summary series] technical system of Internet server: high performance database index
- ts流中的pcr与pts计算与逆运算
- Solve Safari browser download file name garbled problem
- 学习小结(关于深度学习、视觉和学习体会)
- Can you do it with only six characters?
猜你喜欢

Px4 adds new applications
![211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]](/img/3b/00bc81122d330c9d59909994e61027.jpg)
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]

Oops, the system is under attack again

Distributed consensus mechanism

虚拟机中安装 macOS 11 big sur

Game mathematical derivation AC code (high precision and low precision multiplication and division comparison) + 60 code (long long) + 20 point code (Full Permutation + deep search DFS)

VC++指定目录下文件按时间排序输出

That's what software testing is all about?!

解决RabbitMQ消息丢失与重复消费问题

【计算机网络】学习笔记,第三篇:数据链路层(谢希仁版)
随机推荐
Python loop distinction (while loop and for loop)
Review the cloud computing application scenarios you didn't expect (Part 1)
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
Python learning Day1 -- Basic Learning
Which is more worth starting with the difference between vivos7e and vivos7
哔哩哔哩常用api
Cloud Alibabab笔记问世,全网详解仅此一份手慢无
计算机网络基本概念(五)局域网基本原理
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
Px4 adds new applications
Julia 是如何风靡起来的?
Template linked list learning
print( 'Hello,NumPy!' )
vivoS7e和vivoS7的区别 哪个更值得入手
M 端软件产品设计思虑札记 - 知乎
搜索引擎的日常挑战_4_外部异构资源 - 知乎
年轻一代 winner 的程序人生,改变世界的起点藏在身边
Improvement of rate limit for laravel8 update
5g + Ar out of the circle, China Mobile Migu becomes the whole process strategic partner of the 33rd China Film Golden Rooster Award