Hi,
I'm running into a performance issue in my B4J app.
At startup, I'm loading thousands of items into a List. Later, as the app runs, I send multiple FCM messages per second (typically 3–5 per second). Before sending each FCM message, I check whether a topic exists in the List using .IndexOf().
The problem is that over time, this check starts to slow things down significantly. The app begins to lag and struggle to keep up with the rate of messages. If I remove the check and send the FCM messages directly (without checking the List), everything runs smoothly without lag.
Out of curiosity, I asked ChatGPT for suggestions (as a guide only), and it pointed out that .IndexOf() on a List has linear time complexity (O(n)). So, with a large List, each lookup can be slow. It recommended using a Map instead, since lookups in those structures are generally O(1), making them much faster for this kind of check.
I understand ChatGPT isn't always perfect with coding advice, so I wanted to ask is it true that using a Map will give me better performance than a List for this use case?
Or is there another recommended way to check if a value exists in memory before processing the FCM message?
I'm running into a performance issue in my B4J app.
At startup, I'm loading thousands of items into a List. Later, as the app runs, I send multiple FCM messages per second (typically 3–5 per second). Before sending each FCM message, I check whether a topic exists in the List using .IndexOf().
The problem is that over time, this check starts to slow things down significantly. The app begins to lag and struggle to keep up with the rate of messages. If I remove the check and send the FCM messages directly (without checking the List), everything runs smoothly without lag.
Out of curiosity, I asked ChatGPT for suggestions (as a guide only), and it pointed out that .IndexOf() on a List has linear time complexity (O(n)). So, with a large List, each lookup can be slow. It recommended using a Map instead, since lookups in those structures are generally O(1), making them much faster for this kind of check.
I understand ChatGPT isn't always perfect with coding advice, so I wanted to ask is it true that using a Map will give me better performance than a List for this use case?
Or is there another recommended way to check if a value exists in memory before processing the FCM message?