

Ask HN: Architecture vs. Performance? - waffenklang

Hi,<p>as working on an interesting project, i face a recurring problem which i still struggle on at programming.<p>The problem I work on is simply an image parsing (language independed). I know _a_ solution of this problem, i've done it before, but i still have the feeling about, how can i solve this better.<p>The structure of this problem is: 
- load the image (say bmp)
- search the image for certain byte pattern
- create a list of this pattern and search for nearby patterns
- save the results as new list of structures<p>So the schoolbook solution would be doing all this step by step. This would also allow to cleanly separate each steps in a certain architecture which would allow some kind of modify-less reuse.<p>But i also have some solutions in mind, which merges some of these steps to reduce the memory consumption and reduce the iterations done on the data, but then they result in a structure oriented architecture which results in the need of review, rewrite when reusing it. The architecture would finally be a monolithic "x to y converter" architecture.<p>I know its the all time weighting which is to be decided by creating such an algorithm, but maybe you know some more variants which is not just black and white and takes profit from both views.<p>Thanks.
======
dkersten
If you keep them as separated independent steps, it may be possible to
pipeline the processing over multiple cores (that is, while one core performs
step one on the next pattern, step two is being performed on another core on
the previous pattern)[1]. If this is possible, it may be possible to offset
the performance benefits that a monolithic approach would have.

But as sillysaurus says, architecture over performance until performance
becomes an issue. Multicore pipelining is a performance optimisation, so its
something I would read up on to be prepared for it, but don't try it until you
feel you need more performance. Also don't try build it yourself - use a
library. Finally, if that still doesn't give you the performance you need,
start thinking about merging components together. Profile before thinking too
much about performance (but by all means, keep performance in mind so your
architecture can be modified to be higher performance later).

[1] If you're using C++, I personally recommend
<http://threadingbuildingblocks.org/> If you're using another language, it may
still be worth taking a peek at the documentation (especially the section on
pipelines) to get a feel for what I mean.

------
sillysaurus
Always favor architecture over performance, until performance becomes
impossible to ignore.

