Saturday, December 6, 2014

Performance wrecks composability

Usually one should look after the app performance in parallel with app development. And that is because performance can't be (easily) added afterwards.
Let say, you have a sorted list of integers. And you need to process them using binarySearch.
 
binarySearch(items)

In the next version of the app, there is a new requirement to process the subset of items. The straightforward way is to make a copy of items, take the required subset of items and process the copy as before.
 
copy(items, itemsCopy)
filterOut(itemsCopy)
assert(itemsCopy == subset)
binarySearch(itemsCopy)


This solution is composable, in the sense, that you build it using existent components (binarySearch). But it may not be quick enough. A performant way is to create a flavor of binary search, which can operate on a subset of given items.

binarySearchWrecked(items, itemPredicate)

The new requirement of processing the subset of items leads to deep changes in the former code. The composability is gone.

You may read how Walter Bright value the composability here.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete