Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教个问题,json.encode的对象比较大时,encode会慢,并且会卡住UI,改如何解决? #285

Closed
GanZhiXiong opened this issue Feb 24, 2019 · 5 comments

Comments

@GanZhiXiong
Copy link

image

这个问题困扰我一天了,麻烦您解答下,谢谢啦!🙂

@CarGuo
Copy link
Owner

CarGuo commented Feb 24, 2019

你的问题可以在项目里复现那?一般而言网络端返回的数据也是在Furture内处理完之后在给View层显示。虽然Dart是单线程模式,但是异步能更好的分配调度,貌似我还没遇到你说的。

@GanZhiXiong
Copy link
Author

可以复现啊。
我写成下面这样也不行
image
issueHeaderViewModel是一个对象,通过调试发现json.encode比较慢导致UI卡住的,json.encode慢,是因为issueHeaderViewModel这个对象比较大导致的,下面图片是issueHeaderViewModel这个对象
image
json.encode好像不能异步。

@CarGuo
Copy link
Owner

CarGuo commented Feb 25, 2019

真的数据特别大的话,用 isolate 吧

@CarGuo CarGuo closed this as completed Feb 26, 2019
@GanZhiXiong
Copy link
Author

@CarGuo 谢谢提示,我用compute解决了,下面是我的代码
image
但是字符串比较大的话,insert会有一点慢,导致insert的时候卡住UI,下面是你写的insert代码
image
我有尝试将db.insert(name, toMap(fullName, number, dataMapString));这段代码用compute来调用,试过很多次都失败了,失败原因与db这个对象有关,具体我就不知了。期待你下个版本将数据库操作改为isolate,因为有时候数据量大,比较耗时就会卡住UI

@CarGuo
Copy link
Owner

CarGuo commented Feb 27, 2019

应该是跨线程了,后续会尝试增加isolate的

@CarGuo CarGuo mentioned this issue Nov 21, 2019
@w497763094 w497763094 mentioned this issue Mar 10, 2020
@JevonShi JevonShi mentioned this issue Mar 10, 2020
@HaobinXu HaobinXu mentioned this issue Mar 20, 2020
@luan823230 luan823230 mentioned this issue Mar 24, 2020
@hzg1105 hzg1105 mentioned this issue Jun 14, 2020
@wangkr wangkr mentioned this issue Jul 4, 2020
@jayVRIY jayVRIY mentioned this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants