Skip to content

Variable Expansion: ScriptProperty ToStrings are slow to perform #1686

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

Closed
JustinGrote opened this issue Jan 27, 2022 · 7 comments
Closed

Variable Expansion: ScriptProperty ToStrings are slow to perform #1686

JustinGrote opened this issue Jan 27, 2022 · 7 comments
Assignees
Labels

Comments

@JustinGrote
Copy link
Collaborator

JustinGrote commented Jan 27, 2022

image

Per @SeeminglyScience it's probably because the ToString is trying to marshal to the pipeline thread and deadlocking.

@ghost ghost added the Needs: Triage Maintainer attention needed! label Jan 27, 2022
@JustinGrote JustinGrote changed the title Debug Variable Expansion hangs on certain complex classes Debug Variable Expansion hangs on certain Powershell classes Jan 27, 2022
@JustinGrote JustinGrote self-assigned this Jan 27, 2022
@JustinGrote JustinGrote added Area-Debugging Issue-Bug A bug to squash. Needs-Repro-Info and removed Needs: Triage Maintainer attention needed! labels Jan 27, 2022
@JustinGrote JustinGrote changed the title Debug Variable Expansion hangs on certain Powershell classes Variable Expansion Hangs on Powershell Class Array with custom ToString Jan 27, 2022
@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Jan 28, 2022
@JustinGrote
Copy link
Collaborator Author

@SeeminglyScience looks like it's not hard-hanging, just a performance issue. Could this have to do with the marshaling still?

Capture.mp4

@JustinGrote
Copy link
Collaborator Author

Narrowed it down to this loop for enumerables that is "slow", I'll dig deeper into VariableDetails later.

foreach (var item in enumerable)
{
childVariables.Add(
new VariableDetails(
"[" + i++ + "]",
item));
}

@SeeminglyScience
Copy link
Collaborator

@SeeminglyScience looks like it's not hard-hanging, just a performance issue. Could this have to do with the marshaling still?

Yep!

In certain circumstances (like this one) it will timeout after 250ms and then just invoke it anyway from a different thread (while still targeting the same runspace) potentially causing state corruption. So I'd say that still perfectly explains it and potentially makes it a little bit more scary.

@JustinGrote
Copy link
Collaborator Author

Here's the culprit:

If you set it to null instead of SafeToString(), everything is fast again.

@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Jan 28, 2022

More specifically:

@SeeminglyScience how would I get this obj.ToString() method on the correct invocation? It does feel like about a 250ms delay on each invocation.

@JustinGrote JustinGrote changed the title Variable Expansion Hangs on Powershell Class Array with custom ToString ScriptProperty ToStrings are slow to perform Jan 30, 2022
@JustinGrote JustinGrote changed the title ScriptProperty ToStrings are slow to perform Variable Expansion: ScriptProperty ToStrings are slow to perform Jan 30, 2022
@JustinGrote
Copy link
Collaborator Author

Adding @SeeminglyScience as I've hit my limits on figuring this out for now :)

@andyleejordan
Copy link
Member

And fixed, with your test too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants