mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +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",
|
"accessibilityIdentifier",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val jsonMapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
||||||
|
|
||||||
internal fun countRouteScreens(treeJson: String): Int {
|
internal fun countRouteScreens(treeJson: String): Int {
|
||||||
if (treeJson.isBlank()) return 0
|
if (treeJson.isBlank()) return 0
|
||||||
return try {
|
return try {
|
||||||
val mapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
val root = jsonMapper.readTree(treeJson)
|
||||||
val root = mapper.readTree(treeJson)
|
|
||||||
countRouteScreens(root)
|
countRouteScreens(root)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
0
|
0
|
||||||
@@ -158,8 +159,7 @@ private fun countRouteScreens(
|
|||||||
internal fun structuralHash(treeJson: String): String {
|
internal fun structuralHash(treeJson: String): String {
|
||||||
if (treeJson.isBlank()) return ""
|
if (treeJson.isBlank()) return ""
|
||||||
return try {
|
return try {
|
||||||
val mapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
|
val root = jsonMapper.readTree(treeJson)
|
||||||
val root = mapper.readTree(treeJson)
|
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
walkForStructuralHash(root, builder)
|
walkForStructuralHash(root, builder)
|
||||||
builder.toString()
|
builder.toString()
|
||||||
@@ -873,9 +873,7 @@ class MaestroDriverBackend(private val serial: String?) : DriverBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun hierarchy(): String =
|
override fun hierarchy(): String =
|
||||||
com.fasterxml.jackson.module.kotlin.jacksonObjectMapper().writeValueAsString(
|
jsonMapper.writeValueAsString(driver.contentDescriptor(false))
|
||||||
driver.contentDescriptor(false),
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun recentLogs(sinceUnixMillis: Long, minLevel: String) =
|
override fun recentLogs(sinceUnixMillis: Long, minLevel: String) =
|
||||||
readLogcat(serial, sinceUnixMillis, minLevel)
|
readLogcat(serial, sinceUnixMillis, minLevel)
|
||||||
|
|||||||
Reference in new issue
Block a user