Skip to content

Use pfgrep instead of QShell grep when possible#2429

Merged
worksofliam merged 9 commits intocodefori:masterfrom
NattyNarwhal:pfgrep
Aug 14, 2025
Merged

Use pfgrep instead of QShell grep when possible#2429
worksofliam merged 9 commits intocodefori:masterfrom
NattyNarwhal:pfgrep

Conversation

@NattyNarwhal
Copy link
Copy Markdown
Contributor

pfgrep is a fast alternative to QShell grep. It aims to be much faster and support the full spectrum of PCRE regular expression functionality.

In my testing, searching for the string Qp0l in QSYSINC/H shows:

  • qshell grep: ~11 seconds
  • pfgrep v0.2: ~8 seconds
  • pfgrep v0.3: ~2 seconds

Quite a big improvement!

Questions include:

  • Should VS Code offer to point you to where to download pfgrep? It's not yet in the IBM repository, but we do have our own repo, RPMs available, and it can be built from source.
  • With faster search, doing things like regular expressions or searching across multiple files/libraries goes from tedious to quite possible. That's out of scope for this PR, but would be quite nice to add. Same deal for regular expressions instead of fixed strings.
  • If you do need any features in pfgrep, let me know. I can prioritize things that VS Code needs.

Changes

Description of change here.

How to test this PR

Examples:

  1. Run the test cases
  2. Expand view A and right click on the node
  3. Run 'Execute Thing' from the command palette

Checklist

  • have tested my change
  • have created one or more test cases
  • updated relevant documentation
  • Remove any/all console.logs I added
  • have added myself to the contributors' list in CONTRIBUTING.md

@worksofliam
Copy link
Copy Markdown
Member

Should VS Code offer to point you to where to download pfgrep? It's not yet in the IBM repository, but we do have our own repo, RPMs available, and it can be built from source.

This is the main question. I suspect the best we can do is offer a page in our docs (under Tips) specifically for getting pfgrep and what the benefits are.

@NattyNarwhal
Copy link
Copy Markdown
Contributor Author

Might want to wait for next version, I'm working on -f flag support (saving us from having to escape) and inverting behaviour of -t (making it unnecessary for the sake of the unit test).

@worksofliam
Copy link
Copy Markdown
Member

@NattyNarwhal I don't know if you're interested, but we have a major codebase change in the last week, so it might be worth fixing up this PR.

@NattyNarwhal
Copy link
Copy Markdown
Contributor Author

I'll push out an update to pfgrep this week and rebase.

@worksofliam
Copy link
Copy Markdown
Member

@NattyNarwhal I think your test cases need to be moved over to the newer search.test.ts file, which can be tested without launching VS Code.

https://github.com/codefori/vscode-ibmi/blob/master/src/api/tests/suites/search.test.ts

@NattyNarwhal
Copy link
Copy Markdown
Contributor Author

NattyNarwhal commented Feb 3, 2025

I did move the search tests over to the API tests suite; should I revert the ones in the non-API tests suite side?

[pfgrep][pfgrep] is a fast alternative to QShell grep. It aims to be
much faster and support the full spectrum of PCRE regular expression
functionality.

In my testing, searching for the string `Qp0l` in `QSYSINC/H` shows:

- qshell grep: ~11 seconds
- pfgrep v0.2: ~8 seconds
- pfgrep v0.3: ~2 seconds

Quite a big improvement!

Questions include:

- Should VS Code offer to point you to where to download pfgrep? It's
  not yet in the IBM repository, but we do have our own repo, RPMs
  available, and it can be built from source.
- With faster search, doing things like regular expressions or searching
  across multiple files/libraries goes from tedious to quite possible.
  That's out of scope for this PR, but would be quite nice to add. Same
  deal for regular expressions instead of fixed strings.
- If you do need any features in pfgrep, let me know. I can prioritize
  things that VS Code needs.

[pfgrep]: https://github.com/SeidenGroup/pfgrep
By default pfgrep includes the full record, including whitespace.
Maybe this should be changed, but this is what it does now; use -t
to match semantics of qsh grep.

Note that this will need pfgrep v0.3.2; there was a bug in character
trimming in previous versions.
We don't have skips I think, so this may be weird.
@NattyNarwhal
Copy link
Copy Markdown
Contributor Author

I've rebased this for the ASP handling changes.

@worksofliam
Copy link
Copy Markdown
Member

@NattyNarwhal Good news - it's time to actually get this merged. I need the PR updated with the latest from master, then I will test it, and try the test cases, and we're good to go. Thanks and sorry for the delay.

@NattyNarwhal NattyNarwhal temporarily deployed to testing_environment August 12, 2025 15:50 — with GitHub Actions Inactive
@NattyNarwhal NattyNarwhal temporarily deployed to testing_environment August 12, 2025 15:52 — with GitHub Actions Inactive
Comment thread src/api/Search.ts
directory: connection.sysNameInAmerican(`${asp ? `/${asp}` : ``}/QSYS.LIB/${library}.LIB/${sourceFile}.FILE`)
});
} else {
const command = `/usr/bin/grep -inHR -F "${sanitizeSearchTerm(searchTerm)}" ${memberFilter}`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something we need to do in the future is not use the hardcoded grep here, but instead use grep from remoteFeatures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Though looking at it, we might have a problem using remote features with two different versions of grep (since they share a name and key). Ignore this for now.

Copy link
Copy Markdown
Member

@worksofliam worksofliam left a comment

Choose a reason for hiding this comment

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

Tests are passing. Thank you and sorry for the wait.

@worksofliam worksofliam merged commit b0b1f04 into codefori:master Aug 14, 2025
3 checks passed
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.

2 participants