網站首頁 編程語言 正文
引言
List在iOS中有懶加載的特性,但是在MacOS中會一次性加載完List中的所有的數據。并沒有懶加載的特性。
所以在MacOS的List中當數據量巨大時,會存在巨大的性能瓶頸。
var body: some View {
List(){
ForEach(currentSectionModel) { (sectionModel) in
Section(header:
HStack {
Text("section")+Text(sectionModel.word).font(.title).foregroundColor(.red)
}.frame(height:35)
) {
ForEach(currentSectionModel, id: \.self) { (wordModel) in
Text(wordModel.word)
}
}
}
}
當數據量達到15000條時, 在16寸i9的mbp上加載時長需要4.53s
這個時候建議使用 ScrollView + LazyVStack(macOS 11, iOS14支持)
ScrollView {
LazyVStack {
}
}
來獲取巨大性能提升
var body: some View {
ScrollView {
LazyVStack {
ForEach(currentSectionModel) { (sectionModel) in
Section(header:
HStack {
Text("section")+Text(sectionModel.word).font(.title).foregroundColor(.red)
}.frame(height:35)
) {
ForEach(currentSectionModel, id: \.self) { (wordModel) in
Text(wordModel.word)
}
}
}
}
}.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
currentSectionModel = storeData
}
}
}
實測加載15000 條數據加載時長為31ms 加載時長為原來的 0.0068倍。 因為只加載了顯示的部分,所以性能提升巨大。
原文鏈接:https://juejin.cn/post/7138687207426457630
相關推薦
- 2022-11-13 Python?wheel文件詳細介紹_python
- 2022-01-31 Nginx的平滑重啟和平滑升級
- 2022-04-17 實時檢測文件夾變化,及時同步文件到服務器python 腳本
- 2022-05-17 NoSQL中的“BASE”特性
- 2022-05-01 C#中的三種定時計時器Timer用法介紹_C#教程
- 2022-12-23 利用Python實現簡易計算器的示例代碼_python
- 2022-08-14 PyTorch中torch.utils.data.DataLoader簡單介紹與使用方法_pytho
- 2022-06-17 Android實現回彈ScrollView的原理_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支