Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room State Cache saved too often #771

Open
uriesk opened this issue Jul 13, 2024 · 2 comments
Open

Room State Cache saved too often #771

uriesk opened this issue Jul 13, 2024 · 2 comments
Labels
performance Things taking too long to get done

Comments

@uriesk
Copy link

uriesk commented Jul 13, 2024

The room state cache gets saved to disk on almost all Room::change events.
That state can be multiple MB and is freshly written on every new message.
Is this necessary or is it possible to limit this?

@uriesk
Copy link
Author

uriesk commented Jul 13, 2024

JFYI i am in a room with hundreds of users and storing the cache takes >20ms producing a 4MB file.

diff --git a/Quotient/connection.cpp b/Quotient/connection.cpp
index 1474ddc3..78befbef 100644
--- a/Quotient/connection.cpp
+++ b/Quotient/connection.cpp
@@ -1422,6 +1422,9 @@ void Connection::saveRoomState(Room* r) const
     if (!d->cacheState)
         return;
 
+    QElapsedTimer et;
+    et.start();
+
     QFile outRoomFile { stateCacheDir().filePath(
         SyncData::fileNameForRoom(r->id())) };
     if (outRoomFile.open(QFile::WriteOnly)) {
@@ -1435,6 +1438,8 @@ void Connection::saveRoomState(Room* r) const
         qCWarning(MAIN) << "Error opening" << outRoomFile.fileName() << ":"
                         << outRoomFile.errorString();
     }
+
+    qCDebug(PROFILER) << "Room state cache for" << r->id() << "generated in" << et;
 }
 
 void Connection::saveState() const

@KitsuneRal
Copy link
Member

This was made as low-maintenance way to store the room state back before we had to have a database. I think saving the most recent state is valuable to make sure it doesn't get lost in case of crashes but if we save it to the database instead of a CBOR file we could at least save it in a more fine-grained manner, into a file that is already open anyway.

@KitsuneRal KitsuneRal added enhancement A feature or change request for the library performance Things taking too long to get done and removed enhancement A feature or change request for the library labels Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Things taking too long to get done
Projects
Status: 0.9 - To Do
Development

No branches or pull requests

2 participants