Message storage for chat application

I'm relatively new to SolidJS and I'm currently building a chat application. It connects to the chat server via a websocket connection. I have the following questions related to message storage: 1) My niave approach is for each chatroom, to have a signal that is an array of messages. UI elements (i.e. message bubbles) are rendered based on this signal. It then occured to me that if the user keeps this app running for a long time w/o closing the browser that both the signal and the page (appending new speech bubbles into the DOM) can grow to a large size. Should I worry about this? Is there a way to control the size of a signal? Perhaps "trim" it when it exceeds a size of 100? 2) How does Discord's web app handle this?
2 Replies
bigmistqke
bigmistqke•2w ago
1. Should I worry about this? - mm not sure 🤔 I think, probably not until some tipping point. Question is where is that tipping point? and I am not really sure. You could measure how much text weighs? Virtualisation is probably the first low hanging fruit i would look into. 2. Is there a way to control the size of the argument - yes. I would do it simply on the websocket listener: once it exceeds some treshhold, when setting the signal just slice a part of it. You could either save it to localStorage, so that you can get it back if you scroll up, or request it from the server
zulu
zulu•2w ago
Should I worry about this?
yes, if you care about memory usage if your application keeps aggregating messages in memory memory will keep growing. this will be the simplest solution however. other things might include the local caching like suggested above and potentially switching to active pulling instead of pure WS message subscription but complexity will adds up

Did you find this page helpful?