Skip to content

Commit

Permalink
Improve Client creation and build performance (#341)
Browse files Browse the repository at this point in the history
* logging and tests

* remove logs

* add an optional inboxId for performance

* push up all the logging

* clean up the logging

* bump the version

* bump bindngs

* fix linter
  • Loading branch information
nplasterer authored Dec 3, 2024
1 parent 48a9df8 commit 1a2d6a6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xmtp.android.library

import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking
Expand All @@ -12,6 +13,7 @@ import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.walletAddress
import uniffi.xmtpv3.GenericException
import java.security.SecureRandom
import java.util.Date
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -474,4 +476,62 @@ class ClientTest {
}
}
}

@Test
fun testCreatesADevClientPerformance() {
val key = SecureRandom().generateSeed(32)
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fakeWallet = PrivateKeyBuilder()
val start = Date()
val client = runBlocking {
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
appContext = context,
dbEncryptionKey = key
)
)
}
val end = Date()
val time1 = end.time - start.time
Log.d("PERF", "Created a client in ${time1 / 1000.0}s")

val start2 = Date()
val buildClient1 = runBlocking {
Client().build(
fakeWallet.address,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
appContext = context,
dbEncryptionKey = key
)
)
}
val end2 = Date()
val time2 = end2.time - start2.time
Log.d("PERF", "Built a client in ${time2 / 1000.0}s")

val start3 = Date()
val buildClient2 = runBlocking {
Client().build(
fakeWallet.address,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.DEV, true),
appContext = context,
dbEncryptionKey = key
),
inboxId = client.inboxId
)
}
val end3 = Date()
val time3 = end3.time - start3.time
Log.d("PERF", "Built a client with inboxId in ${time3 / 1000.0}s")

assert(time2 < time1)
assert(time3 < time1)
assert(time3 < time2)
assertEquals(client.inboxId, buildClient1.inboxId)
assertEquals(client.inboxId, buildClient2.inboxId)
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 964a227c
Version: f6f9af92
Branch: main
Date: 2024-11-26 17:49:43 +0000
Date: 2024-12-03 20:02:58 +0000
Loading

0 comments on commit 1a2d6a6

Please sign in to comment.