Re: Cost of constructing a communication path vs. sending a message
Chris Jones <[email protected]> Thu, 16 Sep 2010 22:41:11 -0700
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On 09/16/2010 04:03 AM, Mike Kristoffersen wrote: > Looking at the code it seems like constructing a protocol is much more > expensive than just sending a message - so in a case like this where we > have two objects communicating over time, is it then the best choice to > create the connection between them once, and use this connection to > communicate over time - or is it really better to (re-)create the > connection each time it is needed? - Is there a significant cost to > having a connection open all the time? There's not a general answer to that question. it depends on the problem. I don't know exactly what problem you're solving here, but the "request protocol" pattern with Constructor/__delete__ encapsulating the request might be what you want. Depending on what start/stop really mean, tracking nested and overlapping requests can become tricky, and you'd likely end up duplicating the actor-management logic. Creating/destroying an actor is cheap, essentially |new FooActor()/delete actor|| and a hash table insert/delete on both sides. Sending a message with IPC is much much more expensive than constructing/registering/unregistering/deleting an actor. Cheers, Chris