The raw distance to an item is calculated in a relatively simple way; as the eagle flies mole burrows direct distance, ignoring paths. This value is what is calculated and used whenever a dwarf wants a certain item or material. Therefore, the selection method is;
1) Populate list of potential items.
2) Calculate distance to each.
3) Select the 'closest'.
4) Calculate path to this item.
Let's just assume this is how it works. Obviously as forts get bigger, the selection method takes up more and more time. Here's what needs to change.
1. A workshop should be able to designate a stockpile to draw from.
2. When a workshop job needs an item, it looks for it in the associated stockpile.
3. If Stockpile doesn't have the item needed, the search reverts back to the old method.
4. If a workshop has no designated stockpile, the search reverts back to the old method.
This results in most jobs only looking for the closest item from a handful of items, instead of every item in the fort. It also allows some control over the material used for a job by controlling the material in the stockpile.