Design Solution - Pre-Processing
When you are developing some system, you will come across a module or a task that takes longer to process than you would want. Or you might be in a situation where you may need to reduce the time it takes for performing a task.
After an amount of standard optimizations, there comes a point where you can push it no more. That is when, you can start thinking about what is called pre-processing. This is not something radically new. It is used by search algorithms, where you create some indexes or caches before hand - way before the actual search is performed. Databases provide the ability to create indexes that reduces the response time of a SELECT at a later point in time.
A similar design approach, in terms of working out a given module would invovle quite similar steps, no matter what it does.
- Identify the different subtasks, or smaller chunks of the process. Most of the cases, a particular task would have several sub-tasks, or phases in which the process takes place. Recognize each phase of the logic.
- Identify which of them is time critical, and which are not. Some of the tasks would be time critical in the sense that, it has to be done right at that point in time. Some other sub-tasks, could actually be performed before hand.
- Identify if there are any additional tasks that can be performed before hand, that would increase the speed of the task in question.
- Perform the non time critical sub-tasks, or phases before hand. Thus, when the actual task is performed, it will perform better and give a better turn around time.
Note that this approach may not be applicable in all cases. Also, such approach would increase the complexity of the code - the logic to perform one task is basically spread across the timeline, and analyzing such a setup requires a little more effort. There would be other impacts like increased use of space/memory.