Skip to content

Commit

Permalink
Firestore: Choose DEFAULT_RELATIVE_INDEX_READ_COST_PER_DOCUMENT value…
Browse files Browse the repository at this point in the history
… based on the browser, rather than hardcoding 8 (#7929)
  • Loading branch information
dconeybe authored Jan 8, 2024
1 parent 6ea51fb commit d7ace80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/witty-comics-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'firebase': patch
'@firebase/firestore': patch
---

Tweak the automatic index creation parameters to use more optimal values for the platform/browser detected at runtime.
20 changes: 16 additions & 4 deletions packages/firestore/src/local/query_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import { getUA, isSafari } from '@firebase/util';

import {
LimitType,
newQueryComparator,
Expand Down Expand Up @@ -47,6 +49,7 @@ import { LocalDocumentsView } from './local_documents_view';
import { PersistencePromise } from './persistence_promise';
import { PersistenceTransaction } from './persistence_transaction';
import { QueryContext } from './query_context';
import { SimpleDb } from './simple_db';

const DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE = 100;

Expand All @@ -55,10 +58,19 @@ const DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE = 100;
* (([index, docKey] + [docKey, docContent]) per document in the result set)
* / ([docKey, docContent] per documents in full collection scan) coming from
* experiment [enter PR experiment URL here].
* TODO(b/299284287) Choose a value appropriate for the browser/OS combination,
* as determined by more data points from running the experiment.
*/
const DEFAULT_RELATIVE_INDEX_READ_COST_PER_DOCUMENT = 8;
function getDefaultRelativeIndexReadCostPerDocument(): number {
// These values were derived from an experiment where several members of the
// Firestore SDK team ran a performance test in various environments.
// Googlers can see b/299284287 for details.
if (isSafari()) {
return 8;
} else if (SimpleDb.getAndroidVersion(getUA()) > 0) {
return 6;
} else {
return 4;
}
}

/**
* The Firestore query engine.
Expand Down Expand Up @@ -113,7 +125,7 @@ export class QueryEngine {
DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE;

relativeIndexReadCostPerDocument =
DEFAULT_RELATIVE_INDEX_READ_COST_PER_DOCUMENT;
getDefaultRelativeIndexReadCostPerDocument();

/** Sets the document view to query against. */
initialize(
Expand Down

0 comments on commit d7ace80

Please sign in to comment.