7 ms·
At work I hit this issue just the other week. Customers reported performance issues. The issue was that they were pushing more data than we expected, but then a
by magicalhippo 7y ago
At work I hit this issue just the other week. Customers reported performance issues. The issue was that they were pushing more data than we expected, but then again we should have expected that...
Some intricate core code had to do like 10-15 queries per invoice line. Each is quick, but it adds up when you have 10k lines. The code my coworker wrote to do this was written in a per-line way.
Now, since this code was called from other parts of our program, where it might just operate on a single line, I couldn't just cache willy-nilly inside the module. If so I'd have to introduce some calls to invalidate the caches or whatnot. Easy to miss and easy to screw up and get stale data.
However, if instead the API had been batch oriented from the start, it would still work fine on a single line, but also allow for more optimizations for actual batches. The cases where it was called for a single line at a time was when the user was punching through, so being sub-optimal for that would not be an issue.
Gonna be fun trying to disentangle this and try to make it batch friendly...
- triztian 7y agoSeems like a good option would be to implement a second version that has the batch API but leave the line oriented one as is for use by the callers expect it to behave in a per-line oriented way.
- magicalhippo 7y agoYeah, still won't be easy to integrate the batch optimizations now, since all the code in this module is written with the single-line-at-a-time assumption.
- spockz 7y agoIt seems to me that this would be an area where something like reactive streams excel at. The interface is by default streaming and the code dealing with the database could decide to buffer the incoming stream to an optimal amount for creating a query. (Of course only buffering until a maximum latency was reached.) This way neither the producer nor the consumer need to be aware of the exact buffer requirements and the whole can be optimised using back pressure.
- magicalhippo 7y agoWould be interesting to try, sadly not any library support in the language we use.
- Retric 7y agoThat opens things up for a host of long term maintenance issues. It might still be worthwhile, but it’s worth a serious discussion at a minimum.
- vhvjkyhkogvv 7y agoIf the single line one delegates to the batch one it should solve most of them.
- deleted 7y ago[deleted]
- hinkley 7y agostarting with the innermost functions, especially those with no external caller, pluralize the function name and change the argument to be a list/array. Leave a thunking function at the old name that wraps the request and unwraps the response. Lather rinse repeat until the entire module has been fixed, and start pushing it into the slowest callers.