Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode groups sequentially instead of as async tasks #460

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions example/src/tests/groupPerformanceTests.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-extra-non-null-assertion */
import { group } from 'console'

Check warning on line 2 in example/src/tests/groupPerformanceTests.ts

View workflow job for this annotation

GitHub Actions / lint

'group' is defined but never used
import Config from 'react-native-config'
import { privateKeyToAccount } from 'viem/accounts'
import { Client, Group } from 'xmtp-react-native-sdk'

import { Test, assert, createClients } from './test-utils'

Check warning on line 7 in example/src/tests/groupPerformanceTests.ts

View workflow job for this annotation

GitHub Actions / lint

'assert' is defined but never used
import { convertPrivateKeyAccountToSigner } from './tests'
import { supportedCodecs } from '../contentTypes/contentTypes'

Check warning on line 9 in example/src/tests/groupPerformanceTests.ts

View workflow job for this annotation

GitHub Actions / lint

'supportedCodecs' is defined but never used

export const groupPerformanceTests: Test[] = []
let counter = 1
Expand Down Expand Up @@ -51,33 +51,33 @@
return messages
}

// test('testing large group listing with metadata performance', async () => {
// const [alixClient, boClient] = await createClients(2)
test('testing large group listing with metadata performance', async () => {
const [alixClient, boClient] = await createClients(2)

// await createGroups(alixClient, [boClient], 10)
await createGroups(alixClient, [boClient], 50, 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`)
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`)

// start = Date.now()
// await alixClient.conversations.syncGroups()
// end = Date.now()
// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`)
start = Date.now()
await alixClient.conversations.syncGroups()
end = Date.now()
console.log(`Alix synced ${groups.length} groups in ${end - start}ms`)

// 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.syncGroups()
end = Date.now()
console.log(`Bo synced ${groups.length} groups in ${end - start}ms`)

// start = Date.now()
// groups = await boClient.conversations.listGroups()
// end = Date.now()
// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`)
start = Date.now()
groups = await boClient.conversations.listGroups()
end = Date.now()
console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`)

// return true
// })
return true
})

// test('testing large groups with large members and messages performance', async () => {
// const [alixClient] = await createClients(1)
Expand Down Expand Up @@ -492,6 +492,7 @@

const [alixGroup] = await createGroups(alixClient, peers, 1, 10)

console.log('Creating groups')
let start = Date.now()
let messages = await alixGroup.messages()
let end = Date.now()
Expand Down Expand Up @@ -579,7 +580,7 @@
console.log(
`Bo loaded ${messages.length} messages in ${end - start}ms (should have been 20)`
)

Check warning on line 583 in example/src/tests/groupPerformanceTests.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
await createMessages(frankieGroup!!, 5)
await createMessages(boGroup!!, 5)
start = Date.now()
Expand Down
24 changes: 9 additions & 15 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,27 +387,21 @@ public class XMTPModule: Module {
return results
}
}

AsyncFunction("listGroups") { (inboxId: String) -> [String] in
guard let client = await clientsManager.getClient(key: inboxId) else {
throw Error.noClient
}
let groupList = try await client.conversations.groups()
return try await withThrowingTaskGroup(of: String.self) { taskGroup in
for group in groupList {
taskGroup.addTask {
await self.groupsManager.set(group.cacheKey(inboxId), group)
return try GroupWrapper.encode(group, client: client)
}
}

var results: [String] = []
for try await result in taskGroup {
results.append(result)
}

return results

var results: [String] = []
for group in groupList {
await self.groupsManager.set(group.cacheKey(inboxId), group)
let encodedGroup = try GroupWrapper.encode(group, client: client)
results.append(encodedGroup)
}

return results
}

AsyncFunction("listAll") { (inboxId: String) -> [String] in
Expand Down
Loading