Skip to content

Commit

Permalink
perf: rootCache
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 18, 2024
1 parent 5a2455a commit 24c57a8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ class A11yContext(
private var parentCache = LruCache<AccessibilityNodeInfo, AccessibilityNodeInfo>(MAX_CACHE_SIZE)
var rootCache: AccessibilityNodeInfo? = null

private fun clearNodeCache() {
private fun clearNodeCache(t: Long = System.currentTimeMillis()) {
if (META.debuggable) {
val sizeList = listOf(childCache.size(), parentCache.size(), indexCache.size())
if (sizeList.any { it > 0 }) {
Log.d("cache", "clear cache -> $sizeList")
}
}
rootCache = null
lastClearTime = t
if (rootCache?.packageName != topActivityFlow.value.appId) {
rootCache = null
}
try {
childCache.evictAll()
parentCache.evictAll()
Expand All @@ -61,14 +64,12 @@ class A11yContext(
private fun clearNodeCacheIfTimeout() {
if (appChangeTime != lastAppChangeTime) {
lastAppChangeTime = appChangeTime
lastClearTime = System.currentTimeMillis()
clearNodeCache()
return
}
val t = System.currentTimeMillis()
if (t - lastClearTime > 30_000L) {
lastClearTime = t
clearNodeCache()
clearNodeCache(t)
}
}

Expand All @@ -83,7 +84,7 @@ class A11yContext(
if (interruptInnerKey == interruptKey) return
interruptInnerKey = interruptKey
val rule = currentRule ?: return
if (!activityRuleFlow.value.currentRules.contains(rule)) return
if (!activityRuleFlow.value.currentRules.any { it === rule }) return
if (rule.isPriority()) return
if (META.debuggable) {
Log.d("guardInterrupt", "中断 rule=${rule.statusText()}")
Expand Down

0 comments on commit 24c57a8

Please sign in to comment.