Skip to content
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

Merged
merged 2 commits into from
Aug 26, 2021

Conversation

nealkruis
Copy link
Member

@nealkruis nealkruis commented Aug 11, 2021

Pull request overview

I expect:

  • 6-9% improvement for Mac OS clang builds
  • 1-2% improvement for Linux gcc builds
  • Unsure about Windows MSVC builds

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@nealkruis nealkruis added Defect Includes code to repair a defect in EnergyPlus Performance Includes code changes that are directed at improving the runtime performance of EnergyPlus NotIDDChange Code does not impact IDD (can be merged after IO freeze) labels Aug 11, 2021
@nealkruis nealkruis added this to the EnergyPlus 9.6 Release milestone Aug 11, 2021
@nealkruis nealkruis self-assigned this Aug 11, 2021
Copy link
Collaborator

@mitchute mitchute left a 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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Collaborator

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?

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(

Copy link
Collaborator

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).

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Collaborator

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.

@mitchute
Copy link
Collaborator

I'm not sure what to make of this.

Screen Shot 2021-08-26 at 7 17 08 AM

The Windows CI badge is showing a warning, but this isn't a warning over on the CI page. I'm not going to worry about it right now. If there's an actual warning we can clean that up in a later PR. Merging.

@mitchute mitchute merged commit 40edf3b into develop Aug 26, 2021
@mitchute mitchute deleted the fix-get-zone-air-loop-equip branch August 26, 2021 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus NotIDDChange Code does not impact IDD (can be merged after IO freeze) Performance Includes code changes that are directed at improving the runtime performance of EnergyPlus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ManageZoneAirLoopEquipment unnecessarily calls GetZoneAirLoopEquipment on every iteration
10 participants