✅ Is it worth to use stackalloc here?
Hey, I have this:
I think it is not good to create sseEvent every second without any memory clean. Is it worth to use stackalloc here?
22 Replies
would this not work?
Classes cannot be stackalloced.
they can be in .net 9
Link?
Iirc there’s escape analysis coming, but that’s something the JIT may do as an optimization.
i must've made that fact up in my head somehow
i swear i was very sure it was true
yeah, it was just an example and I missed this
but anyway.. I can change class to struct or record struct for example
is it worth it?
you'll have to benchmark that yourself. i wouldn't think it's really worth it, since it would be a fairly large struct
let's imagine we should somehow optimize objects creation. How can we do it?
why should you optimize? have you checked that this is a bottleneck at all? there are likely many other aspects that are much more prone to causing performance degradation besides instantiating a lot of classes...
because its async, u probably will have bad times with such a big struct anyway, if u pass value types around u are copying the data over.
since its async, u cant utilize
ref
s in any way either, so it will be most likely slower.
if u want to reduce allocations, the better fit here would be most likely object pooling, which comes with its own down sides(unless you use c# 13)
u are missing the point, u would have to pass the
ref
to the awaited async method, which wont happen to be allowed like ... evermhhh
right
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
hm yes, sse is good for this things
actually I don't need signalr
signalr can choose websockets, sse etc
I just need sse
if its just server->client i wouldnt bother with websockets/signalr either
ws is good but i need sse here, thats why I use text/event-stream
anyway thanks for helping
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
read docs
MDN Web Docs
Using server-sent events - Web APIs | MDN
Developing a web application that uses server-sent events is straightforward. You'll need a bit of code on the server to stream events to the front-end, but the client side code works almost identically to websockets in part of handling incoming events. This is a one-way connection, so you can't send events from a client to a server.
and https://www.strathweb.com/2024/07/built-in-support-for-server-sent-events-in-net-9/
I don't need signalr in my opinion
why should I install the whole library just for heartbeat
I can do it manually
also use signalr and force it to use just sse is weird
you would have to split by \n and add a data: for each line
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View