I am sure you all know this. But the problem increases as the number of styles grows. In looking at the code, I am convinced that the problem can be found in the fact that when borders are drawn, the cell style is retrieved, the border is applied, and all styles are searched for a matching style. I one is not found, then a new one is created (even if it is not going to ultimately be used because this happens for each border segment individually), and if colors are included, the process will take 2 to 4 times as long because only one style property is applied at a time. You can see the exponential growth in time as borders are added around ranges.
If you were to create a setCellProperty(Cell, Workbook, Map<String, Object>) where the map is a set of cell style properties, you could then use the Map.putAll method to apply a whole set of border properties all in one step, and then search for, and create if necessary, the final style, rather than searching and creating each intermediate style. The benefit, if you discount the fact that the number of styles is growing all the time you are drawing borders is that you are going to get up to a 75% time reduction, and another 50% beyond that if border colors are being used. Now empirical evidence suggests that I end up with 70 to 80% unused cell styles due to my border drawing activities. And since the real time in drawing borders is in searching for a style match, if we simply avoid creating all those intermediate styles, we will see additional gains. A second method of speeding things up would be to hash and cache the styles so that instead of comparing the entire map, we just compare hash values. Maybe a combination of the two methods would be the best of both worlds. Am I crazy?
