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

极端条件测试性能,普通圆角功能 #79

Open
scsfwgy opened this issue Nov 16, 2020 · 2 comments
Open

极端条件测试性能,普通圆角功能 #79

scsfwgy opened this issue Nov 16, 2020 · 2 comments

Comments

@scsfwgy
Copy link
Contributor

scsfwgy commented Nov 16, 2020

场景:做交易相关,在深度列表中显示当前委托小圆点,使用RView设置圆角,只有这一个功能。因为交易特殊性,需要高频刷新。应用打开后,十多分钟后卡顿、ANR以及频繁GC出现。也是花了很多时间才排查到RWidget的问题。换成系统组件,用原始xml形式设置圆角,问题解决。不是在这找RWidgetHelper的茬,因为整个应用都在用这个组件,非常好用。希望可以找到根本原因,解决掉。已知阴影效果有很大的性能问题;简单圆角功能,在极端条件下才会有问题。
举例

<com.ruffian.library.widget.RView
               android:id="@+id/att_rv_dot"
               android:layout_width="4dp"
               android:layout_height="4dp"
               app:corner_radius="2dp"
               app:background_normal="@color/wrapper_k_red" />

测试代码:



/**
     * @param rWidget 是否是RWidget。
     * 测试结果:在这样的极端条件下,使用RWidget每次创建(35个View添加到容器中)耗时是使用系统控件耗时的3倍左右。
     * 使用RWidget gc垃圾回收更加频繁和耗时更加长。在几分钟内应用就会因为anr和OOM挂掉。但是使用系统组件测试时,很长时间都不会挂掉(也会进行gc,但是好很多)。
     * 这里只是使用最基本的设置圆角功能。希望可以找到根本原因。
     */
    fun test(rWidget: Boolean) {
        val subscribe = Observable.interval(100, TimeUnit.MILLISECONDS).compose(RxUtils.rxObSchedulerHelper())
                .subscribe {
                    val begin = System.currentTimeMillis()
                    val linearLayout = LinearLayout(mContext)
                    linearLayout.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                    linearLayout.orientation = LinearLayout.HORIZONTAL
                    for (i in 0..35) {
                        linearLayout.addView(if (rWidget) createRViews() else createViews())
                    }
                    att_ll_container.addView(linearLayout)
                    Log.d(TAG, "test: " + (System.currentTimeMillis() - begin))
                }
        addDisposable(subscribe)

    }

    /**
     * 使用RWidget控件测试View创建
     */
    fun createRViews(): RView {
        val randomNum = RandomUtils.getRandomNum(0, 1)
        val color = ResourcesUtils.getColor(if (randomNum == 0) R.color.wrapper_k_red else R.color.wrapper_k_green)
        //att_rv_dot.helper.backgroundColorNormal = color
        val view = RView(mContext)
        view.layoutParams = ViewGroup.LayoutParams(SizeUtils.dp2px(4f), SizeUtils.dp2px(4f))
        view.helper.backgroundColorNormal = color
        view.helper.cornerRadius = SizeUtils.dp2px(2f).toFloat()
        return view
    }

    /**
     * 使用系统控件测试View创建
     */
    fun createViews(): View {
        val randomNum = RandomUtils.getRandomNum(0, 1)
        val color = ResourcesUtils.getDrawable(if (randomNum == 0) R.drawable.shape_commom_dot_red else R.drawable.shape_commom_dot_green)
        val view = View(mContext)
        view.layoutParams = ViewGroup.LayoutParams(SizeUtils.dp2px(4f), SizeUtils.dp2px(4f))
        view.background = color
        return view
    }



@scsfwgy
Copy link
Contributor Author

scsfwgy commented Nov 16, 2020

#38

@scsfwgy
Copy link
Contributor Author

scsfwgy commented Nov 16, 2020

@RuffianZhong

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

1 participant