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

[Fixed][P0][Performance][RootTicket][CZGithub SlowScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). #35

Open
geekaurora opened this issue May 3, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@geekaurora
Copy link
Owner

geekaurora commented May 3, 2021

My Doc

Description

  • CZGithubReactAppKit - Slow when scrolling - CZWebImage.
  • Even scroll at same screen - scroll up/down. (As it updates visitedDate for each image)

Sub ticket

Reasons: CZDiskCacheManager in CZHttpFile package

  • CZDiskCacheManager.flushCachedItemsDictToDisk(): Without flushCachedItemsDictToDisk() = 60 FPS

CZWebImage - Call Stack

1. Write fileInfo - setCachedItemsDict

  • CZHttpFileManager.downloadFile() // OK
  • CZDiskCacheManager.getCachedFile(withUrl:) // OK
  • update visiteData // OK: removed
  • CZDiskCacheManager.setCachedItemsDict(key:subkey:value:skipIfKeyNotExists:) // OK: DebounceTaskScheduler
  • CZDiskCacheManager.cachedItemsDictLockWrite(:) // OK: DebounceTaskScheduler
  • CZMutexLock.writeLock(.barrier) (Block main thread) // OK: DebounceTaskScheduler
  • flushCachedItemsDictToDisk() (DiskIO: shouldn't write for each cache file getting - visitDate: batchUpdate) // OK: DebounceTaskScheduler

2. Write downloaded file - with .barrier async: [Risky][Won't Fix] write file with .atomic option.

Sub ticket: #38

Investigation

  • Remove CZWebImage: 60FPS (Always: even load more)

Solutions

Without flushCachedItemsDictToDisk(): 60 FPS

1. DebounceTaskScheduler - cachedItemsDict: merges the same tasks with gap and only executes the last task.
2. Write file: remove .barrier - CZDiskCacheManager.ioQueue.async()

  • Avoid blocking: writing files is very frequent
  1. Flag shouldEnableCachedItemsDict: indicates whether to save cached file information. e.g. url, size. Defaults to false.
  • CZWebImage = false, CZHttpFile = true - large files.

Added back

  • [CZHttpFile] httpManager.cancelTask(with: url) // 2022.11.25

[Risky?] Not Added Back!!

Other improvements

  • CZHttpFileManager.downloadFile
    • getCache()
    • ioQueue.async(): it was sync() - block main thread when get cache.
  • ioQueue: QoS - from .userInitiated to .default (Faster: image slower)

Sub improvements

  • Remove visitedDate - clean cache with createdDate

No need

  • cachedItemsDict file.write(): Async - ioQueue (separate serialQueue?)
@geekaurora geekaurora changed the title [Performance][SlowWhenScrolling ] CZWebImage [Performance][SlowWhenScrolling ] LoadMore - CZWebImage May 30, 2021
@geekaurora geekaurora changed the title [Performance][SlowWhenScrolling ] LoadMore - CZWebImage [Performance][SlowWhenScrolling ] LoadMore / CZWebImage May 30, 2021
@geekaurora geekaurora changed the title [Performance][SlowWhenScrolling ] LoadMore / CZWebImage [Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - scrolling. May 31, 2021
@geekaurora geekaurora changed the title [Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - scrolling. [Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). May 31, 2021
@geekaurora
Copy link
Owner Author

Xcode Profile logs

1.33 s 83.2% 0 s 0x1024aa84e CZWebImage
CZHttpFile
CZUtils

@geekaurora geekaurora transferred this issue from another repository May 31, 2021
@geekaurora geekaurora changed the title [Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). [MileStone][Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). May 9, 2022
@geekaurora geekaurora reopened this May 9, 2022
@geekaurora geekaurora changed the title [MileStone][Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). [P0][Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). May 9, 2022
@geekaurora geekaurora changed the title [P0][Performance][SlowWhenScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). [P0][Performance][RootTicket][CZGithub SlowScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). Nov 25, 2022
@geekaurora geekaurora changed the title [P0][Performance][RootTicket][CZGithub SlowScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). [Fixed][P0][Performance][RootTicket][CZGithub SlowScrolling ] CZWebImage consumes 83.2% CPU time - CZDiskCacheManager.flushCachedItemsDictToDisk(). Nov 25, 2022
@geekaurora geekaurora added the bug Something isn't working label Nov 25, 2022
@geekaurora geekaurora self-assigned this Nov 25, 2022
@geekaurora geekaurora pinned this issue Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant