-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary allocations in GetZoneAirLoopEquipment routine every iteration #8963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine. I'll merge it up with develop one more time then we can merge it.
@@ -192,13 +196,6 @@ namespace ZoneAirLoopEquipmentManager { | |||
Array1D_bool lNumericBlanks(2); // Logical array, numeric field input BLANK = .TRUE. | |||
bool DualDuctRecircIsUsed; // local temporary for deciding if recirc side used by dual duct terminal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this group of seemingly small arrays suck up that much time being needlessly allocated? That's incredible. And these local arrays aren't even necessary. There's state.dataIPShortCut->cAlphaArgs
etc. available to use. Not suggesting you need to change that here, but something to watch for elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful! There is a fourPipeBeamFactory call at line 417 that will overwrite the dataIPShortCut variables. So I would think these locals are needed. The only time dataIPShortCut variables can be used is if the getInput in question has no calls to other getInput functions that use the dataIPShortCut variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @rraustad, I'm confused. Where are you looking?
Here?
EnergyPlus/src/EnergyPlus/ZoneAirLoopEquipmentManager.cc
Lines 414 to 418 in 68b20c8
state.dataDefineEquipment->AirDistUnit(AirDistUnitNum).airTerminalPtr = FourPipeBeam::HVACFourPipeBeam::fourPipeBeamFactory( | |
state, state.dataDefineEquipment->AirDistUnit(AirDistUnitNum).EquipName(1)); | |
if (state.dataDefineEquipment->AirDistUnit(AirDistUnitNum).UpStreamLeak || | |
state.dataDefineEquipment->AirDistUnit(AirDistUnitNum).DownStreamLeak) { | |
ShowSevereError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this group of seemingly small arrays suck up that much time being needlessly allocated? That's incredible.
They do! I think I mentioned in the most recent 10X "lesson" that std::vector
and ArrayXD
should not be used as local variables unless absolutely necessary because of the overhead of calling constructors (malloc) and destructors (free).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at develop. Yes, that call will getInput the 4pipebeam and overwrite those dataIPShortCut variables mentioned. Low level models that do not do any mining of data can use dataIPShortCut variables (e.g., state.dataIPShortCut->cAlphaArgs). Higher level models that get data from other models usually need to use locals for the getObjectItem call (e.g., Array1D_string AlphArray(5)). This was over 10 years ago so it's not on anyone's radar. Once we switch over to json all these arrays go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @mjwitte said, there are no changes needed regarding this discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful! There is a fourPipeBeamFactory call at line 417 that will overwrite the dataIPShortCut variables. So I would think these locals are needed. The only time dataIPShortCut variables can be used is if the getInput in question has no calls to other getInput functions that use the dataIPShortCut variables.
Put a pin in this. Re-entrant code is not a good design pattern. Re-entrant code with variables that are effectively global is really not a good design pattern. This should be "flattened out" somehow.
Pull request overview
I expect:
Pull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.