I have the next class which instantiated about 40 million times and all its instances take about 80% of all process memory (more than 15GB).
class MyClass
{
String Field1
String Field2
String Field3
int Field4
int Field5
float Field6
SomeEnum Field7
Boolean Field8
Boolean Field9
Boolean Field10
Byte Field11
Byte Field12
}
I want somehow to optimize this class, but not sure what can I do in this case. I thought about to combine boolean field to a single byte or customize fields alignment, but not sure if it worse and if it will not break something. Also tried to change it to be a structure, but got performance problems in existing code without significant improvement.
So, what can be done here to decrease memory usage without serious performance degradation?
This code will run mostly on x64 server, x32 only in development.
EDIT:
This is service that supposed very fast return a result that depends on all this data. Very fast here is about 20ms-150ms. So all data is hashed and sorted, and every field in this class is used almost in every request to the service. May be something here designed bad, but design is not an issue here, and I just can't redesign it right now from scratch.