Hacker News new | ask | show | jobs
by rkalla 1381 days ago
I used an approach similar to Peter's here to both an old streaming parsing library as well as a GUI (event handling) library -- effectively, re-use the same instance of the event shell with new data every time an event fired and copy the data out if you need to retain it for a long-lived operation or persistence, otherwise calculate and move on... the reduction in object creation overhead was significant and performance increase was around +30% for doing this in the two individual use-cases... BUT, the API was like a loaded gun pointed at your face.

I knew what I was doing (with it) so it wasn't a problem, but if I over open sourced the API and provided it as a library I would envision a large portion of the population trying to handle the events in a multi-threaded context or throwing them into a List only to find the values changing on them during use (while the parser was still running on another thread).

Performance was so tempting, but usability-face-shot-gun was the greater evil.

1 comments

Reusing your objects can be confusing for other developers. You need to be careful with anything exposed via an API, however internally you can me more optimised.