1515 * limitations under the License.
1616 */
1717
18+ import { getUA , isSafari } from '@firebase/util' ;
19+
1820import {
1921 LimitType ,
2022 newQueryComparator ,
@@ -47,6 +49,7 @@ import { LocalDocumentsView } from './local_documents_view';
4749import { PersistencePromise } from './persistence_promise' ;
4850import { PersistenceTransaction } from './persistence_transaction' ;
4951import { QueryContext } from './query_context' ;
52+ import { SimpleDb } from './simple_db' ;
5053
5154const DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE = 100 ;
5255
@@ -55,10 +58,19 @@ const DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE = 100;
5558 * (([index, docKey] + [docKey, docContent]) per document in the result set)
5659 * / ([docKey, docContent] per documents in full collection scan) coming from
5760 * experiment [enter PR experiment URL here].
58- * TODO(b/299284287) Choose a value appropriate for the browser/OS combination,
59- * as determined by more data points from running the experiment.
6061 */
61- const DEFAULT_RELATIVE_INDEX_READ_COST_PER_DOCUMENT = 8 ;
62+ function getDefaultRelativeIndexReadCostPerDocument ( ) : number {
63+ // These values were derived from an experiment where several members of the
64+ // Firestore SDK team ran a performance test in various environments.
65+ // Googlers can see b/299284287 for details.
66+ if ( isSafari ( ) ) {
67+ return 8 ;
68+ } else if ( SimpleDb . getAndroidVersion ( getUA ( ) ) > 0 ) {
69+ return 6 ;
70+ } else {
71+ return 4 ;
72+ }
73+ }
6274
6375/**
6476 * The Firestore query engine.
@@ -113,7 +125,7 @@ export class QueryEngine {
113125 DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE ;
114126
115127 relativeIndexReadCostPerDocument =
116- DEFAULT_RELATIVE_INDEX_READ_COST_PER_DOCUMENT ;
128+ getDefaultRelativeIndexReadCostPerDocument ( ) ;
117129
118130 /** Sets the document view to query against. */
119131 initialize (
0 commit comments