Skip to content

Conversation

@vinayakparashar
Copy link
Collaborator

Added performance optimization for iteration execution

});
}
// if custom parallel iterations is true, then set the areIterationsParallelized to true
this.areIterationsParallelized = this.options?.customParallelIterations ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this state not saved in the Partition Manager instance?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this state is only used by the run instance. based on it's value run instance will decide whether to use the partition manager or no.

this.snrHash = null; // we populate it in the first SNR call

done();
return done();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we've moved some code to utils, but there's still a lot of duplicate code from the waterfall command. Why can't it queue the waterfall or find a better way to avoid this duplication?

Copy link
Collaborator

@KhudaDad414 KhudaDad414 Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a separate function to handle the SNR logic, which reduces duplicate code.

While we could make changes to the ⁠waterfall command, we prefer to avoid modifying it or introducing additional conditional statements. Doing so could negatively affect its performance and make the overall logic harder to understand. For this reason, we have chosen to implement a completely new command for parallel runs, even if it means some code duplication.

Comment on lines 143 to 162
/**
* Starts a parallel iteration
* @param {Number} index - The index of the partition to run
* @param {Object} localVariables - Local variables for the iteration
* @param {Function} callback - The callback to call when the iteration is complete
*/
startParallelIteration (index, localVariables, callback) {
this.partitionManager.runSinglePartition(index, localVariables, callback);
},

/**
* Stops a parallel iteration
* @param {Number} index - The index of the partition to stop
* @param {Function} callback - The callback to call when the iteration is complete
*/
stopParallelIteration (index, callback) {
this.partitionManager.stopSinglePartition(index, callback);
},


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see these methods being used. Do we still need them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, these are methods exposed for external orchestration not used inside the code directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, move these to the prototype object of parallel.command.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

result && result._variables &&
(this.state._variables = new sdk.VariableScope(result._variables));

// persist the pm.variables for the next request in the current iteration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since each partition needs to track it's own variables, we are updating the variables for that partition only. So we do not affect other partitions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a helper function in partition manager, something like: this.partitionManager.persistVariables(result._variables).

@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 91.52542% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.20%. Comparing base (c2a4a7a) to head (21b3b0c).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
lib/runner/partition-manager.js 90.83% 5 Missing and 7 partials ⚠️
lib/runner/extensions/parallel.command.js 88.46% 5 Missing and 1 partial ⚠️
lib/runner/run.js 72.72% 2 Missing and 1 partial ⚠️
lib/runner/partition.js 93.10% 1 Missing and 1 partial ⚠️
lib/runner/util.js 96.07% 0 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (91.52%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1525       +/-   ##
============================================
+ Coverage    38.59%   75.20%   +36.61%     
============================================
  Files           46       49        +3     
  Lines         3537     3779      +242     
  Branches      1027     1081       +54     
============================================
+ Hits          1365     2842     +1477     
+ Misses        2074      713     -1361     
- Partials        98      224      +126     
Flag Coverage Δ
integration 65.41% <78.30%> (?)
legacy 36.80% <24.74%> (?)
unit 41.99% <64.06%> (+3.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

// the process tick
backpack.ensure(userback, this) && userback();

this.partitionManager && this.partitionManager.clearPools();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what situations can this.partitionManager be undefined?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Production code, never. but since partitionManager isn't a part of the main execution loop (which is waterfall), this is just a defensive measure for future proofing and run object manipulation.
let me know if this check should be removed.

// the process tick
backpack.ensure(userback, this) && userback();

this.partitionManager && this.partitionManager.clearPools();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just .clear() or .dispose().

// do so in a try block to ensure it does not hamper the process tick
backpack.ensure(userback, this) && userback();
}
this.partitionManager && this.partitionManager.triggerStopAction();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should include this in this.partitionManager.dispose(), which clears and triggers the stop.

result && result._variables &&
(this.state._variables = new sdk.VariableScope(result._variables));

// persist the pm.variables for the next request in the current iteration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a helper function in partition manager, something like: this.partitionManager.persistVariables(result._variables).

Comment on lines 143 to 162
/**
* Starts a parallel iteration
* @param {Number} index - The index of the partition to run
* @param {Object} localVariables - Local variables for the iteration
* @param {Function} callback - The callback to call when the iteration is complete
*/
startParallelIteration (index, localVariables, callback) {
this.partitionManager.runSinglePartition(index, localVariables, callback);
},

/**
* Stops a parallel iteration
* @param {Number} index - The index of the partition to stop
* @param {Function} callback - The callback to call when the iteration is complete
*/
stopParallelIteration (index, callback) {
this.partitionManager.stopSinglePartition(index, callback);
},


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, move these to the prototype object of parallel.command.

@appurva21 appurva21 merged commit 455b308 into develop Sep 18, 2025
17 of 21 checks passed
@appurva21 appurva21 deleted the chore/iteration-optimizations branch September 18, 2025 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants