diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index cddbe1582..26de287d2 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -752,20 +752,11 @@ class XMTPModule : Module() { val params = ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?: "") val order = getConversationSortOrder(sortOrder ?: "") - val start = Date() val conversations = client.conversations.listConversations(order = order, limit = limit) - val end = Date() - logV("LOPI Loaded ${conversations.size} DMs in ${end.time - start.time}ms") - - val start2 = Date() - val convos = conversations.map { conversation -> + conversations.map { conversation -> ConversationContainerWrapper.encode(client, conversation, params) } - val end2 = Date() - logV("LOPI Encoded ${convos.size} DMs in ${end2.time - start2.time}ms") - - convos } } diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index 49ec81182..e610aaa70 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -162,300 +162,300 @@ test('test compare V2 and V3 dms', async () => { return true }) -// test('testing large group listings with ordering', async () => { -// await beforeAll(1000, 10, 10) - -// let start = Date.now() -// let groups = await alixClient.conversations.listGroups() -// let end = Date.now() -// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) - -// await groups[5].send({ text: `Alix message` }) -// await groups[50].send({ text: `Alix message` }) -// await groups[150].send({ text: `Alix message` }) -// await groups[500].send({ text: `Alix message` }) -// await groups[700].send({ text: `Alix message` }) -// await groups[900].send({ text: `Alix message` }) - -// let start2 = Date.now() -// let groups2 = await alixClient.conversations.listGroups( -// { -// members: false, -// consentState: false, -// description: false, -// creatorInboxId: false, -// addedByInboxId: false, -// isActive: false, -// lastMessage: true, -// }, -// 'lastMessage' -// ) -// let end2 = Date.now() -// console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`) -// assert( -// end2 - start2 < end - start, -// 'listing 1000 groups without certain fields should take less time' -// ) - -// start = Date.now() -// await alixClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 1000 cached groups should take less than a .1 second' -// ) - -// start = Date.now() -// await boClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) - -// start = Date.now() -// await boClient.conversations.syncAllGroups() -// end = Date.now() -// console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 30000, -// 'Syncing all 1000 groups should take less than a 30 second' -// ) - -// start = Date.now() -// groups = await boClient.conversations.listGroups() -// end = Date.now() -// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) - -// start2 = Date.now() -// groups2 = await boClient.conversations.listGroups( -// { -// members: false, -// consentState: false, -// description: false, -// creatorInboxId: false, -// addedByInboxId: false, -// isActive: false, -// lastMessage: true, -// }, -// 'lastMessage' -// ) -// end2 = Date.now() -// console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`) -// assert( -// end2 - start2 < end - start, -// 'listing 1000 groups without certain fields should take less time' -// ) - -// return true -// }) - -// test('testing large group listings', async () => { -// await beforeAll(1000) - -// let start = Date.now() -// let groups = await alixClient.conversations.listGroups() -// let end = Date.now() -// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'listing 1000 groups should take less than a 3 second' -// ) - -// start = Date.now() -// await alixClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 1000 cached groups should take less than a .1 second' -// ) - -// start = Date.now() -// await boClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 6000, -// 'syncing 1000 groups should take less than a 6 second' -// ) - -// start = Date.now() -// groups = await boClient.conversations.listGroups() -// end = Date.now() -// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'loading 1000 groups should take less than a 3 second' -// ) - -// return true -// }) - -// test('testing large message listings', async () => { -// await beforeAll(1, 2000) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// let messages = await alixGroup.messages() -// let end = Date.now() -// console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 1000, -// 'listing 2000 self messages should take less than a 1 second' -// ) - -// start = Date.now() -// await alixGroup.sync() -// end = Date.now() -// console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 2000 self messages should take less than a .1 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 3000, -// 'syncing 2000 messages should take less than a 3 second' -// ) - -// start = Date.now() -// messages = await boGroup!.messages() -// end = Date.now() -// console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) -// assert( -// end - start < 1000, -// 'loading 2000 messages should take less than a 1 second' -// ) - -// return true -// }) - -// test('testing large member listings', async () => { -// await beforeAll(1, 1, 50) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// let members = await alixGroup.members -// let end = Date.now() -// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'listing 50 members should take less than a .1 second' -// ) - -// start = Date.now() -// await alixGroup.sync() -// end = Date.now() -// console.log(`Alix synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 members should take less than a .1 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 members should take less than a .1 second' -// ) - -// start = Date.now() -// members = await boGroup!.members -// end = Date.now() -// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 members should take less than a .1 second' -// ) - -// const [davonClient] = await createClients(1) - -// start = Date.now() -// await alixGroup.addMembers([davonClient.address]) -// end = Date.now() -// console.log(`Alix added 1 member in ${end - start}ms`) -// assert(end - start < 100, 'adding 1 member should take less than a .1 second') - -// start = Date.now() -// members = await alixGroup.members -// end = Date.now() -// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 member should take less than a .1 second' -// ) - -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'syncing 50 member should take less than a .1 second' -// ) - -// start = Date.now() -// members = await boGroup!.members -// end = Date.now() -// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) -// assert( -// end - start < 100, -// 'loading 50 member should take less than a .1 second' -// ) - -// return true -// }) - -// test('testing sending message in large group', async () => { -// await beforeAll(1, 2000, 100) - -// const alixGroup = initialGroups[0] -// let start = Date.now() -// await alixGroup.send({ text: `Alix message` }) -// let end = Date.now() -// console.log(`Alix sent a message in ${end - start}ms`) -// assert( -// end - start < 200, -// 'sending a message should take less than a .2 second' -// ) - -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// start = Date.now() -// await boGroup!.prepareMessage({ text: `Bo message` }) -// end = Date.now() -// console.log(`Bo sent a message in ${end - start}ms`) -// assert( -// end - start < 100, -// 'preparing a message should take less than a .1 second' -// ) - -// start = Date.now() -// await boGroup!.sync() -// end = Date.now() -// console.log(`Bo synced messages in ${end - start}ms`) -// assert( -// end - start < 9000, -// 'syncing 2000 messages should take less than a 9 second' -// ) - -// start = Date.now() -// await boGroup!.send({ text: `Bo message 2` }) -// end = Date.now() -// console.log(`Bo sent a message in ${end - start}ms`) -// assert( -// end - start < 100, -// 'sending a message should take less than a .1 second' -// ) - -// return true -// }) +test('testing large group listings with ordering', async () => { + await beforeAll(1000, 10, 10) + + let start = Date.now() + let groups = await alixClient.conversations.listGroups() + let end = Date.now() + console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) + + await groups[5].send({ text: `Alix message` }) + await groups[50].send({ text: `Alix message` }) + await groups[150].send({ text: `Alix message` }) + await groups[500].send({ text: `Alix message` }) + await groups[700].send({ text: `Alix message` }) + await groups[900].send({ text: `Alix message` }) + + let start2 = Date.now() + let groups2 = await alixClient.conversations.listGroups( + { + members: false, + consentState: false, + description: false, + creatorInboxId: false, + addedByInboxId: false, + isActive: false, + lastMessage: true, + }, + 'lastMessage' + ) + let end2 = Date.now() + console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`) + assert( + end2 - start2 < end - start, + 'listing 1000 groups without certain fields should take less time' + ) + + start = Date.now() + await alixClient.conversations.syncGroups() + end = Date.now() + console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 1000 cached groups should take less than a .1 second' + ) + + start = Date.now() + await boClient.conversations.syncGroups() + end = Date.now() + console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + + start = Date.now() + await boClient.conversations.syncAllGroups() + end = Date.now() + console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 30000, + 'Syncing all 1000 groups should take less than a 30 second' + ) + + start = Date.now() + groups = await boClient.conversations.listGroups() + end = Date.now() + console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) + + start2 = Date.now() + groups2 = await boClient.conversations.listGroups( + { + members: false, + consentState: false, + description: false, + creatorInboxId: false, + addedByInboxId: false, + isActive: false, + lastMessage: true, + }, + 'lastMessage' + ) + end2 = Date.now() + console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`) + assert( + end2 - start2 < end - start, + 'listing 1000 groups without certain fields should take less time' + ) + + return true +}) + +test('testing large group listings', async () => { + await beforeAll(1000) + + let start = Date.now() + let groups = await alixClient.conversations.listGroups() + let end = Date.now() + console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 3000, + 'listing 1000 groups should take less than a 3 second' + ) + + start = Date.now() + await alixClient.conversations.syncGroups() + end = Date.now() + console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 1000 cached groups should take less than a .1 second' + ) + + start = Date.now() + await boClient.conversations.syncGroups() + end = Date.now() + console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 6000, + 'syncing 1000 groups should take less than a 6 second' + ) + + start = Date.now() + groups = await boClient.conversations.listGroups() + end = Date.now() + console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) + assert( + end - start < 3000, + 'loading 1000 groups should take less than a 3 second' + ) + + return true +}) + +test('testing large message listings', async () => { + await beforeAll(1, 2000) + + const alixGroup = initialGroups[0] + let start = Date.now() + let messages = await alixGroup.messages() + let end = Date.now() + console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 1000, + 'listing 2000 self messages should take less than a 1 second' + ) + + start = Date.now() + await alixGroup.sync() + end = Date.now() + console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 2000 self messages should take less than a .1 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 3000, + 'syncing 2000 messages should take less than a 3 second' + ) + + start = Date.now() + messages = await boGroup!.messages() + end = Date.now() + console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) + assert( + end - start < 1000, + 'loading 2000 messages should take less than a 1 second' + ) + + return true +}) + +test('testing large member listings', async () => { + await beforeAll(1, 1, 50) + + const alixGroup = initialGroups[0] + let start = Date.now() + let members = await alixGroup.members + let end = Date.now() + console.log(`Alix loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'listing 50 members should take less than a .1 second' + ) + + start = Date.now() + await alixGroup.sync() + end = Date.now() + console.log(`Alix synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 members should take less than a .1 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 members should take less than a .1 second' + ) + + start = Date.now() + members = await boGroup!.members + end = Date.now() + console.log(`Bo loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 members should take less than a .1 second' + ) + + const [davonClient] = await createClients(1) + + start = Date.now() + await alixGroup.addMembers([davonClient.address]) + end = Date.now() + console.log(`Alix added 1 member in ${end - start}ms`) + assert(end - start < 100, 'adding 1 member should take less than a .1 second') + + start = Date.now() + members = await alixGroup.members + end = Date.now() + console.log(`Alix loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 member should take less than a .1 second' + ) + + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'syncing 50 member should take less than a .1 second' + ) + + start = Date.now() + members = await boGroup!.members + end = Date.now() + console.log(`Bo loaded ${members.length} members in ${end - start}ms`) + assert( + end - start < 100, + 'loading 50 member should take less than a .1 second' + ) + + return true +}) + +test('testing sending message in large group', async () => { + await beforeAll(1, 2000, 100) + + const alixGroup = initialGroups[0] + let start = Date.now() + await alixGroup.send({ text: `Alix message` }) + let end = Date.now() + console.log(`Alix sent a message in ${end - start}ms`) + assert( + end - start < 200, + 'sending a message should take less than a .2 second' + ) + + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + start = Date.now() + await boGroup!.prepareMessage({ text: `Bo message` }) + end = Date.now() + console.log(`Bo sent a message in ${end - start}ms`) + assert( + end - start < 100, + 'preparing a message should take less than a .1 second' + ) + + start = Date.now() + await boGroup!.sync() + end = Date.now() + console.log(`Bo synced messages in ${end - start}ms`) + assert( + end - start < 9000, + 'syncing 2000 messages should take less than a 9 second' + ) + + start = Date.now() + await boGroup!.send({ text: `Bo message 2` }) + end = Date.now() + console.log(`Bo sent a message in ${end - start}ms`) + assert( + end - start < 100, + 'sending a message should take less than a .1 second' + ) + + return true +}) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 105524f06..03ee59620 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -651,20 +651,13 @@ public class XMTPModule: Module { let params = ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?? "") let order = getConversationSortOrder(order: sortOrder ?? "") - var start = Date() let conversations = try await client.conversations.listConversations(limit: limit, order: order) - var end = Date() - print("Loaded \(conversations.count) conversations in \(end.timeIntervalSince(start) * 1000)ms from iOS") var results: [String] = [] - start = Date() for conversation in conversations { let encodedConversationContainer = try await ConversationContainerWrapper.encode(conversation, client: client) results.append(encodedConversationContainer) } - end = Date() - print("Loaded \(results.count) conversationContainers in \(end.timeIntervalSince(start) * 1000)ms from iOS") - return results }