I’m looking at updating a crm and order management application that was designed for N number of orders years ago (perhaps ten) but is now handling N x 50 or more orders - so saw lots of performance issues during 2021, etc.
These “orders” are physically produced but within the context of the application they are custom objects. Currently these objects are loaded into a massive array from the database engines; sometimes as many as a million order objects loaded into memory. There is a single array that holds all these, and other “customer” objects reference back to this array (so a customer object references that customer’s orders easily). However for any operation that requires searching through this array, the time is slowly increasing. Additionally the application real time (or as close to it) updates objects in memory with new orders, order status changes, etc, which can come at the rate of a hundred per second, so constantly searching this array to locate the order and apply changes to it can add up.
I was hoping to ping the community to get an opinion of speeding up accessing these orders in memory, as the projection is at least another 25%+ increase in order volume for 2022.
My first thought was to load the order objects into a dictionary, with a key being the database identity of the order. It seems that then order lookup in the dictionary would be much faster, as a dictionary of one million items would be quicker to locate the one that has database identity 123456789 by checking hasKey(identity) and value(identity). The customer object would reference the objects either in an array or the same type of dictionary just containing references back to the main order dictionary.
However, another hitch is that in various places throughout the code base, orders are searched for based not only on the db identity but other attributes such as the internal order id string and version integer or even with the customer’s order id. (for example an order may be for customer 012345 database identity 123456789 order id R789654 ver 2 but the customer’s own id for the order is ABCDEFG.)
Would it be wise to have multiple concurrent dictionaries with references to the primary one? For example, a dictionary whose key is the db identity (as noted above), and second dictionary whose key is the orderid-ver with a reference back to the original dictionary?
As the goal is to simplify and speed up operation, and would require a lot of code changes to move away from the current array based objects, I want to be sure I am on the right path before committing the time to make these changes. So I am hopeful the community can offer their opinions on the things I outlined above. Thank you in advance for any help!