firebase / firebase/firebase-admin-dart
Concurrent request execution is exponentially slow
- Dominant language
- Dart
- Stars
- 177
- Forks
- 70
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 6
Description
**Describe the bug**
Concurrently executing thousands of queries is super slow in dart. For below code it took around ~2s for nodejs version to finish executing and around ~57s for dart version.
**To Reproduce**
The code should call production (actual firestore) APIs and not a local emulator to see the issue.
Dart (Super Slow):
```dart
import 'package:firebase_admin_sdk/firebase_admin_sdk.dart';
import 'package:firebase_functions/firebase_functions.dart';
void main() {
runFunctions((firebase) {
firebase.https.onRequest(name: 'helloWorld', (request) async {
final arr = List.generate(3000, (index) => index);
final firestore = FirebaseApp.instance.firestore();
await Future.wait(
arr.map((index) {
return firestore
.collection('numbers')
.where('number', .equal, index)
.limit(1)
.get();
}),
eagerError: true,
);
return .ok('Yay! Client Exception did not occur.');
});
});
}
```
Typescript (Fast):
```ts
import {initializeApp} from "firebase-admin/app";
import {getFirestore} from "firebase-admin/firestore";
import {onRequest} from "firebase-functions/https";
initializeApp();
export const helloWorld = onRequest(async (_request, response) => {
const arr = Array.from({length: 3000}, (_, index) => index);
const firestore = getFirestore();
await Promise.all(
arr.map((index) => {
return firestore
.collection("numbers")
.where("number", "==", index)
.limit(1)
.get();
}),
);
response.status(200).send("Yay! Client Exception did not occur.");
});
```
**Expected behavior**
The speed of executing thousands of queries concurrently in dart should be as fast as if not faster than nodejs version.
Contributor guide
Assessment
This issue has not been assessed yet.