Skip to content

Slow queries if fetched after other queries #9240

@Byloth

Description

@Byloth

Operating System

Microsoft Windows 11 Pro 24H2

Environment (if applicable)

Google Chrome 139

Firebase SDK Version

11.10.0

Firebase SDK Product(s)

Firestore

Project Tooling

I'm working on WSL2 with: Ubuntu 24.04.3 LTS (GNU/Linux 6.6.87.2-microsoft-standard-WSL2 x86_64).
I'm using: Vue.js app with Vite.js

Detailed Problem Description

I have a dashboard application which shows some statistics collected & saved on Firestore.

There's a switch that allows the user to switch between a daily-basis stats to a hourly-basis one.
The application keeps track of what was the last used configuration so - when the page loads - it automatically uses the last selected config.

When it first load the page (e.g. after an Ctrl+ R), it takes a couple hundreds of milliseconds (like 100 - 200ms) to fetch the query. No matter what the last enabled configuration was.
When the application is already running (e.g. when the user changes the config), the same query might takes even seconds (like 2.500ms to 7.500ms). During this time the page also freezes and stops to be responsive.

These data are stored in 2 different collections: dailyStats & hourlyStats.

Here are the logs I collected about this:

Steps and code to reproduce issue

The code I used to achieve these logs looks something like this:

const _benchmark = async (callback: Function) =>
{
    const start = performance.now();
    const result = await callback();
    const end = performance.now();

    console.log(`Benchmark: ${(end - start).toFixed(3)}ms`);

    return result;
};

const app = initializeApp({ ... });
const firestore = getFirestore(app);

setLogLevel("debug");

async function getHourly()
{
    const reference = collection(firestore, "hourlyStats");

    let snapshot: QuerySnapshot;
    await _benchmark(async () => { snapshot = await getDocs(query(reference, orderBy("date", "asc"))); });

    return snapshot.docs.map((doc) => doc.data());
}
async function getDaily(start: Date, end: Date)
{
    const reference = collection(firestore, "dailyStats");
    const whereCondition = and(where("date", ">=", start), where("date", "<", end));
    const orderByCondition = orderBy("date", "asc");

    let snapshot: QuerySnapshot;
    await _benchmark(async () => { snapshot = await getDocs(query(reference, whereCondition, orderByCondition)); });

    return snapshot.docs.map((doc) => doc.data());
}

await getHourly();
await getDaily(new Date("2025-08-28"), new Date("2025-09-04"));

Right now, I'm unable to share more than this...
It is part of an enterprise project.

I would say... Let's start from here:

  • Is it something already known?
  • Did I miss an existing Issue about this?
  • Is it something intentional?
  • How is it possible that no one has ever experienced / reported something like this?
  • Is it something related to some sort of caching?
    Is it possible to disable it and avoid this problem?

I will prepare and put something together if necessary.


Regarding the last question above...
I've been struggling with this issue since April 2024 (it isn't somethin new), but now some customers are starting to complain...

Honestly, at the time, I was hoping that with some time and some new release of the Firebase SDK this problem would be solved, sooner or later... But now our development team have to face it and solve it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions