ConstraintLayout UI效能分析

2022-07-27 06:12:12 字數 1453 閱讀 4936

constraintlayout, 2023年由google i/o推出,android studio中, constraintlayout已替代relativelayout, 成為hello world的預設布局.

關於constraintlayout的使用就不說了,請看

或者 可以看出constraintlayout的優勢主要體現在兩點

1. 可以更方便的通過視覺化拖拽的方式生成布局(大部分開發者可能更願意用xml**)

2. 複雜布局下終於可以不用一層套一層了

是不是打算把專案裡的布局relativelayout都換成constraintlayout了?等一等...,constraintlayout 效能到底怎麼樣?是不是任何布局都適合用constraintlayout?

簡單寫個布局,對比一下

最簡單的根布局包含幾個textview和imageview,沒有巢狀,可以看出linearlayout是渲染最快的,這個符合預期,重點比較relativelayout和constraintlayout,發現constraintlayout在onmesaure階段

耗時數倍於relativelayout。

再看下簡單巢狀布局constraintlayout表現怎麼樣?

relativelayout和linearlayout作為根布局下,又包含了乙個linearlayout的布局,constraintlayout當然不需要了

這幾種布局下,relativelayout和linearlayout 載入速度相差無幾,constraintlayout的onmesaure又拖後腿了...

深度巢狀的複雜布局沒有試,但relativelayout肯定會隨著巢狀層數的增多 速度越來越慢,這時constraintlayout的優勢便體現出來了

nicolas roard是constraintlayout的開發人員

所以,我的建議是 簡單或者輕度巢狀繼續使用傳統布局(優先選擇linearlayout),涉及到複雜布局及深度巢狀,constraintlayout更方便,效能也能體現出來優勢。

valgrind callgrind效能分析

1.請自行安裝valgrind工具 2.使用工具執行你的應用程式 valgrind tool callgrind sgzj socialserver 3.執行結束後,程式當前目錄生成了乙個檔案callgrind.out.58237 4.python gprof2dot.py f callgrind ...

python效能差 python一些效能分析的技巧

當我們開始精通程式語言時,我們不僅希望實現最終目標,而且希望使我們的程式高效。在這個教程中,我們將學習一些ipython的命令,這些命令可以幫助我們對python 進行時間分析。注意,在本教程中,我建議使用anaconda。1.分析一行 要檢查一行python 的執行時間,請使用 timeit 下面...

golang slice 與list 的效能分析。

一 比較slice 與 list 遍歷建立和新增元素速度。package main import time fmt container list func main fmt.println slice 建立速度 time.now sub t string t time.now l list.new ...