-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performancecore PowerShell engine, interpreter, and runtime performance
Description
Summary of the performance problem
Note: This SO question inspired this suggestion.
Updated based on feedback from @lzybkr below.
# REGULAR, direct invocation of an expression (a `foreach` statement
# that loops 1 million (1e6) times, in this case) - implicitly DOT-SOURCED
(Measure-Command { $result = foreach ($n in 1..1e6) { $n } }).TotalSeconds
# Invocation in CHILD SCOPE, using & { ... }
# 10+ TIMES FASTER.
(Measure-Command { $result = & { foreach ($n in 1..1e6) { $n } } }).TotalSeconds
Sample timings (note the ratio) on macOS:
2.5900995 # DIRECT invocation (implicitly DOT-SOURCED)
0.2580877 # in CHILD SCOPE, via & { ... }
That is, direct invocation was about 10 times slower than invocation via &
.
Possible implementation
See @lzybkr's comments below, which also explains the root cause.
jazzdelightsme and santisq
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performancecore PowerShell engine, interpreter, and runtime performance