Skip to content

Incorrect PLINQ usage in ToolRestoreCommand #10937

@stephentoub

Description

@stephentoub

In this code, the AsParallel() is effectively a nop:

ToolRestoreResult[] toolRestoreResults =
packagesFromManifest
.Select(package => InstallPackages(package, configFile))
.AsParallel().ToArray();

The AsParallel() here is only going to affect the ToArray call, which isn't parallelizable on its own. Presumably the intention was to parallelize the Select.ToArray, in which case the AsParallel needs to be moved to before the Select call:

            ToolRestoreResult[] toolRestoreResults =
                packagesFromManifest
                    .AsParallel()
                    .Select(package => InstallPackages(package, configFile))
                    .ToArray();

If it's not desirable to parallelize the Select call (e.g. if InstallPackages isn't safe to be invoked in parallel or if InstallPackages won't benefit from being invoked in parallel), then the .AsParallel() should just be removed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions