mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
perf(sidecar): reuse a single Jackson ObjectMapper
structuralHash, countRouteScreens, and hierarchy each built a fresh ObjectMapper per call inside the stability poll; the instance is thread-safe and meant to be reused. Hoist one shared val.
This commit is contained in:
1 parent
75281d8e16
commit
80603446a3
1 file changed
+5
-7
@@ -117,11 +117,12 @@ private val ROUTE_TAG_KEYS = setOf(
|
||||
"accessibilityIdentifier",
|
||||
)
|
||||
|
||||
private val jsonMapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
||||
|
||||
internal fun countRouteScreens(treeJson: String): Int {
|
||||
if (treeJson.isBlank()) return 0
|
||||
return try {
|
||||
val mapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
||||
val root = mapper.readTree(treeJson)
|
||||
val root = jsonMapper.readTree(treeJson)
|
||||
countRouteScreens(root)
|
||||
} catch (_: Exception) {
|
||||
0
|
||||
@@ -158,8 +159,7 @@ private fun countRouteScreens(
|
||||
internal fun structuralHash(treeJson: String): String {
|
||||
if (treeJson.isBlank()) return ""
|
||||
return try {
|
||||
val mapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
||||
val root = mapper.readTree(treeJson)
|
||||
val root = jsonMapper.readTree(treeJson)
|
||||
val builder = StringBuilder()
|
||||
walkForStructuralHash(root, builder)
|
||||
builder.toString()
|
||||
@@ -873,9 +873,7 @@ class MaestroDriverBackend(private val serial: String?) : DriverBackend {
|
||||
}
|
||||
|
||||
override fun hierarchy(): String =
|
||||
com.fasterxml.jackson.module.kotlin.jacksonObjectMapper().writeValueAsString(
|
||||
driver.contentDescriptor(false),
|
||||
)
|
||||
jsonMapper.writeValueAsString(driver.contentDescriptor(false))
|
||||
|
||||
override fun recentLogs(sinceUnixMillis: Long, minLevel: String) =
|
||||
readLogcat(serial, sinceUnixMillis, minLevel)
|
||||
|
||||
Reference in new issue
Block a user