You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: Clarify Overlays in architecture and code layout documentation
Updated to provide a detailed explanation of the 'Overlays' component within the Local Store, describing its purpose as a performance-optimizing cache for pending mutations.
Also updated to consistently list 'Overlays' as a component of the directory, aligning with the architectural overview.
Copy file name to clipboardExpand all lines: packages/firestore/devdocs/architecture.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ The SDK is composed of several key components that work together to provide the
19
19
***Remote Table**: A cache of the most recent version of documents as known by the Firestore backend.
20
20
***Mutation Queue**: A queue of all the user-initiated writes (set, update, delete) that have not yet been acknowledged by the Firestore backend.
21
21
***Local View**: A cache that represents the user's current view of the data, combining the Remote Table with the Mutation Queue.
22
+
***Overlays**: A performance-optimizing cache that stores the calculated effect of pending mutations from the Mutation Queue on documents. Instead of re-applying mutations every time a document is read, the SDK computes this "overlay" once and caches it, allowing the Local View to be constructed more efficiently.
22
23
***Remote Store**: The component responsible for all network communication with the Firestore backend. It manages the gRPC streams for reading and writing data, and it abstracts away the complexities of the network protocol from the rest of the SDK.
23
24
***Persistence Layer**: The underlying storage mechanism used by the Local Store to persist data on the client. In the browser, this is implemented using IndexedDB.
24
25
@@ -28,7 +29,7 @@ The architecture and systems within the SDK map closely to the directory structu
28
29
*`api/`: Implements the **API Layer** for the main SDK.
29
30
*`lite-api/`: Implements the **API Layer** for the lite SDK.
30
31
*`core/`: Implements the **Sync Engine** and **Event Manager**.
31
-
*`local/`: Implements the **Local Store**, which includes the **Mutation Queue**, **Remote Table**, **Local View**, and the **Persistence Layer**.
32
+
*`local/`: Implements the **Local Store**, which includes the **Mutation Queue**, **Remote Table**, **Local View**, **Overlays**and the **Persistence Layer**.
32
33
*`remote/`: Implements the **Remote Store**, handling all network communication.
33
34
34
35
For a more detailed explanation of the contents of each directory, see the [Code Layout](./code-layout.md) documentation.
@@ -66,7 +67,7 @@ Here's a step-by-step walkthrough of how data flows through the SDK for a write
66
67
1.**API Layer**: A user initiates a write operation (e.g., `setDoc`, `updateDoc`, `deleteDoc`).
67
68
2.**Sync Engine**: The call is routed to the Sync Engine, which wraps the operation in a "mutation".
68
69
3.**Mutation Queue (in Local Store)**: The Sync Engine adds this mutation to the Mutation Queue. The queue is persisted to the **Persistence Layer** (IndexedDB). At this point, the SDK "optimistically" considers the write successful locally.
69
-
4.**Local View (in Local Store)**: The change is immediately reflected in the Local View, making it available to any active listeners without waiting for backend confirmation.
70
+
4.**Local View (in Local Store)**: The change is reflected in the Local View. This is done by creating or updating a cached **Overlay** for the affected document, making the change efficiently available to any active listeners without waiting for backend confirmation.
70
71
5.**Remote Store**: The Sync Engine notifies the Remote Store that there are pending mutations.
71
72
6.**Backend**: The Remote Store sends the mutations from the queue to the Firestore backend.
72
73
7.**Acknowledgement**: The backend acknowledges the write.
@@ -77,7 +78,7 @@ Here's a step-by-step walkthrough of how data flows through the SDK for a write
77
78
1.**API Layer**: A user attaches a listener to a query (e.g., `onSnapshot`).
78
79
2.**Event Manager**: The Event Manager creates a listener and passes it to the Sync Engine.
79
80
3.**Sync Engine**: The Sync Engine creates a "view" for the query.
80
-
4.**Local View (in Local Store)**: The Sync Engine asks the Local Store for the current documents matching the query. This includes any optimistic local changes from the **Mutation Queue**.
81
+
4.**Local View (in Local Store)**: The Sync Engine asks the Local Store for the current documents matching the query. The Local Store provides these by applying cached **Overlays** on top of the documents to reflect optimistic local changes from the **Mutation Queue**.
81
82
5.**API Layer**: The initial data from the Local View is sent back to the user's `onSnapshot` callback. This provides a fast, initial result.
82
83
6.**Remote Store**: Simultaneously, the Sync Engine instructs the Remote Store to listen to the query on the Firestore backend.
83
84
7.**Backend**: The backend returns the initial matching documents for the query.
Copy file name to clipboardExpand all lines: packages/firestore/devdocs/code-layout.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This document explains the code layout in this repository. It is closely related
6
6
*`api/`: Implements the **API Layer** for the main SDK.
7
7
*`lite-api/`: Contains the entry point of for the lite SDK.
8
8
*`core/`: Contains logic for the **Sync Engine** and **Event Manager**.
9
-
*`local/`: Contains the logic the **Local Store**, which includes the **Mutation Queue**, **Remote Table**, **Local View**, and the **Persistence Layer**.
9
+
*`local/`: Contains the logic the **Local Store**, which includes the **Mutation Queue**, **Remote Table**, **Local View**, **Overlays**, and the **Persistence Layer**.
10
10
*`remote/`: Contains the logic for the **Remote Store**, handling all network communication.
11
11
*`model/`: Defines the internal data models used throughout the SDK, such as `Document`, `DocumentKey`, and `Mutation`. These models are used to represent Firestore data and operations in a structured way.
12
12
*`platform/`: Contains platform-specific code to abstract away the differences between the Node.js and browser environments. This includes things like networking, storage, and timers. This allows the core logic of the SDK to be platform-agnostic.
0 commit comments