Skip to content

Make Select-String faster by not doing extra work - #7673

Merged
Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
powercode:SelectString
Oct 18, 2018
Merged

Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
powercode:SelectString

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Aug 31, 2018 •

Copy link
Copy Markdown
Collaborator

PR Summary

By not tracking context in the common case where Context size is 0, and by not checking if the full name of a FileInfo is a Directory, about 30% of the execution time is cut when piping files into Select-String.

PR Checklist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM
But shouldn't this also use the NoContextTracker?

_globalContextTracker = new ContextTracker(_preContext, _postContext);

@powercode

Copy link
Copy Markdown
Collaborator Author

Paul Higinbotham (@PaulHigin) You are right!

@adityapatwardhan

Copy link
Copy Markdown
Member

Staffan Gustafsson (@powercode) Please address the CodeFactor issues, specifically in new code.

@powercode

Copy link
Copy Markdown
Collaborator Author

Aditya Patwardhan (@adityapatwardhan) Do you want me to fix all it the file or just the new ones? Happy to do both, but more to review if I fix all of them.

@adityapatwardhan

Copy link
Copy Markdown
Member

Staffan Gustafsson (@powercode) Fixing the CodeFactor issues for the code you added / changed should be sufficient. Thanks!

Don't check if fileinfos are directories (they never are).
Don't track context when context size is 0.

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great work!

return s_inputStream;
return _path;
}
get => !_pathSet ? s_inputStream : _path;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

More readable:

get => _pathSet ? _path : s_inputStream; 

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For sure - don't know what I was thinking :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

{
throw PSTraceSource.NewArgumentNullException("value");
}
_includeStrings = value ?? throw PSTraceSource.NewArgumentNullException("value");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could use nameof(value).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Please address comments and we'll merge.

@powercode

Copy link
Copy Markdown
Collaborator Author

Ilya (@iSazonov) I'll have a look this evening.

@iSazonov Ilya (iSazonov) Oct 16, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please revert the remove - we can not change a public contract.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should we change to comment to indicated that this isn't used anywhere?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we shouldn't block the PR and please open new tracking Issue to get PowerShell Committee conclusion.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I force-pushed the revert of the Filename property.

Also removing the non-referenced property FileName.
@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Thanks for great work!

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
By not tracking context in the common case where Context size is 0 (using new NoContextTracker class), and by not checking if the full name of a FileInfo is a Directory, about 30% of the execution time is cut when piping files into Select-String.
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.

4 participants