The user doesn't need to receive the full item data string very often. When the user requests an item change, the server takes the string, convert it to an List<Integer> and does work, and then converts it back to a string and saves the variable. I was doing this so that a string is only sitting in memory instead of a List<Integer>, since GC will clean up all temp Lists.
However, I am wondering if I should just store the List<Integer> using .setProperty when the user logs in and then use .getProperty on a new List to perform changes to prevent converting back and forth between String and List.
What I'm doing now:
Code: Select all
String inventory = user.getVariable("i").getStringValue();
items = Stream.of(inventory.split(","))
.map(String::trim)
.map(Integer::parseInt)
.collect(Collectors.toList());
….
// After modification, resave
String data = inventoryData.stream().map( s -> s.toString()).collect( Collectors.joining( "," ) );
UserVariable inventory = new SFSUserVariable(“i”, data);
What I may change to:
Code: Select all
List<Integer> items = (List<Integer>) user.getProperty("i");
….
// After modification, resave
user.setProperty("i", items);
Which approach seems best ? Is converting between String worth it to save memory vs CPU? Any input is good.