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

Performance Issues #22

Open
Appilog opened this issue Jun 23, 2017 · 6 comments
Open

Performance Issues #22

Appilog opened this issue Jun 23, 2017 · 6 comments

Comments

@Appilog
Copy link

Appilog commented Jun 23, 2017

Hello,
first, thank you very much for sharing your work here!

I have some serious performance problems on tablets where there are e.g. 20 columns and 10 rows.

Is this normal? Do other users also have this issue?
Is there something I can do about, or is it a principal problem with the large number of RecyclerViews?

Thanks!

@zhouchaoyuan
Copy link
Owner

There are some performance problems in low-end devices, but 20 columns and 10 rows in my nexus5 is also have a good performance.What kind of mobile phone do you use to test?

@Appilog
Copy link
Author

Appilog commented Jul 5, 2017

Thanks for your answer!
I don't have the problem on smartphones! On smartphones the performance is relatively ok.
The problem is on tablets, where much more cells are visible at the same time. I use a Galaxy Note 10.1 2014 for testing.

In the meantime I have solved the issues. It works now much more fluent on smartphones AND tablets.

In initWidget() I added the following settings for each RecyclerView:

    .setDrawingCacheEnabled(true);
    .setItemViewCacheSize(itemViewCacheSize);
    .setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

In my case I could also add:

    .setHasFixedSize(true);

Then there were to many calls to the onScrollListeners. To reduce that I added the following lines:

For the horizontal listener (to avoid vertical handling):

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
    {
        if (dy == 0 || Math.abs(dx) > Math.abs(dy))
        {
            return;
        }

...

and at the end of the method:

        for (int i = 0; i < mRecyclerView.getChildCount(); i++)
        {
            //Correct old Y-Positions of previously invisible recycler views while scrolling them in sight
            //from left or right side. Only correct first and last column because this is sufficient and
            //leads to a smoother scrolling
            if ((i == 0 || i == mRecyclerView.getChildCount() - 1) && mRecyclerView.getChildAt(i) instanceof RecyclerView)
            {
                RecyclerView recyclerView1 = (RecyclerView) mRecyclerView.getChildAt(i);
                fastScrollVertical(amountAxisY, recyclerView1);
            }
        }

for the vertical listener (to avoid horizontal handling):

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
    {
        if (dy == 0 || Math.abs(dx) > Math.abs(dy))
        {
            return;
        }

Hope that helps!
Thanks again for sharing your work!!

I'll send you an eMail with some off-topic questions concerning my app!

Thanks!

@dysen2014
Copy link

性能确实有问题, 20行20列 还好 一但大几十行和列 就卡得不行, 检测内存看到快满了。 是不是单元格一直新建,没有替换。 导致我有多少行列就创相应的单元格呢?
@zhouchaoyuan

@zhouchaoyuan
Copy link
Owner

zhouchaoyuan commented Jul 7, 2017

@dysen2014
性能问题在数据大的时候不可避免,这里View肯定是复用的,但是data并没有复用,假如说 50 * 50 的数据,那么就需要有2500个对象(每个单元格需要一个data,这个暂时认为data是一个object),对于这么大的数据内存占用肯定就很大了,这种情况就好比一个listView有2500条数据,这样肯定会遇到性能瓶颈。

对于上面Appilog说的给ExcelPanel里面的每个RecyclerView使用下面的代码

.setDrawingCacheEnabled(true); .setItemViewCacheSize(itemViewCacheSize); .setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

这个时候就可能导致大量的view缓存,内存立马就会爆炸,出现ANR
不过不得不否认Appilog的做法在内存允许的情况下是有性能优化的,但是数据一旦超过一个临界值,后果会比较严重

@zhouchaoyuan
Copy link
Owner

@dysen2014
I'm very glad to hear that you have solved the issues mentioned above using the settings below:

    .setDrawingCacheEnabled(true);
    .setItemViewCacheSize(itemViewCacheSize);
    .setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

So I try the codes like you do, but I found memory is increasing rapidly.

Monitors show the datas below:
image

And here is the datas before configing:
image

I guess that this may have a good performance when the data in some scale. But there are may have some issues(e.g. ARN or crash) when you reach the threshold.

@dysen2014
Copy link

dysen2014 commented Jul 9, 2017 via email

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

3 participants