Skip to content

workspaceContains:*.txt starts a search through the workspace #110510

Closed

Description

@roblourens
  • Install Remote-Containers
  • Connect to an SSH remote, open /
  • Notice long-running rg process

After 84fc970, any local extension with workspaceContains will trigger a search on the remote to activate it. Since the expandPatterns flag is set for workspaceContains searches, this triggers a search like **/devcontainer.json which will be expensive. This will only happen for extensions like Remote-Containers which will be activated locally when in a remote window.

I guess we want either

  • To do a normal file lookup, but on the remote workspace instead of the local. No idea if this is possible
  • To do a search, but without the expandPatterns flag
    • The current effect of this is that workspaceContains:hello.txt will only look for a hello.txt in the root, but workspaceContains:*.txt will search **/*.txt

cc Christof Marti (@chrmarti)

Activity

  1. added
    bug
    search
    remote
    on Nov 12, 2020
  2. self-assigned this
    on Nov 12, 2020
  3. roblourens commented on Nov 12, 2020

    @roblourens
    MemberAuthor

    Alexandru Dima (@alexdima) the code in workspaceContains.ts is called from two places, extHostExtensionService.ts and abstractExtensionService.ts, in what cases are those two used? And is it possible to have the local EH check the fileService on the remote EH while handling this pattern so we can process it without triggering a search?

  4. chrmarti commented on Nov 13, 2020

    @chrmarti
    Collaborator

    Not sure I fully understand, Remote-Containers doesn't use wildcards:

    		"workspaceContains:.devcontainer/devcontainer.json",
    		"workspaceContains:.devcontainer.json",
    

    It makes sense for Remote-Containers to trigger a lookup, e.g., when connected to Remote-WSL we support having a devcontainer.json that can then also be used to reopen the WSL folder in a container.

  5. roblourens commented on Nov 13, 2020

    @roblourens
    MemberAuthor

    Yeah it doesn't, but when a search is triggered through this path then wildcards are added. If possible it would be simplest and fastest to do a lookup for the exact path on the remote, which is what workspaceContains normally does. If we can't do that, like if the local EH doesn't have something like a file service that will end up resolving paths on the remote, then I can change the search to run without the wildcards.

  6. alexdima commented on Nov 18, 2020

    @alexdima
    Member

    This is all rather complex. I will try to write what I know on the topic:

    • checkActivateWorkspaceContainsExtension is called in the extension host process from extHostExtensionService.ts on extension host startup. This is the most simple case in a way: opening a folder or a workspace and all extensions are checked if they use workspaceContains and if they need to be activated.
    • checkActivateWorkspaceContainsExtension is also called from the renderer process from abstractExtensionService.ts when an extension is installed or updated. The idea is that if you install an extension that uses workspaceContains, you'd want it to activate if the workspace contains whatever the extension looks for.

    84fc970 is IMHO perfectly valid. In the remote case, the local extension host cannot access directly the remote filesystem, so it will forcefully issue a search (which AFAIK goes to the renderer process, and then goes to the remote extension host).


    roblourens What I don't understand is what do you mean with the following:

    The current effect of this is that workspaceContains:hello.txt will only look for a hello.txt in the root, but workspaceContains:.txt will search **/.txt
    but when a search is triggered through this path then wildcards are added

    Who is prepending the extra **/ to the search patterns. Is this something recent or has this always been the case? Is it possible to run the search without an extra **/ prepended to the patterns?

    To further clarify, a workspaceContains:*.txt means that the extension wants to be activated if there is at least one .txt file in the root of the folder. A workspaceContains:**/*.txt means that the extension wants to be activated if there is at least one .txt file anywhere in the workspace.

  7. roblourens commented on Nov 19, 2020

    @roblourens
    MemberAuthor

    That makes sense, I didn't know that extensions are activated in the workspace when they are installed, thanks.

    In the remote case, the local extension host cannot access directly the remote filesystem, so it will forcefully issue a search (which AFAIK goes to the renderer process, and then goes to the remote extension host).

    That's right, I think it would be less load during startup to do a stat through some file service that makes the same trip rather than spawning rg, but if we don't have something like that already, it's fine. This particular situation is not really common.


    Bad news is, I realized that what I explained does not make sense, I looked into it and see that it seems that I changed it to handle workspaceContains:*.txt as **/*.txt last year, while fixing a different issue, I set expandPatterns: true just so that the pattern would be split on commas, but this also adds the **.

    #68969
    then #69862

    It's possible that some extension now depends on this now but it's bad enough that I should fix it. I can check popular extensions, reach out to them, whatever, but yeah obviously *.txt should not search the whole workspace.

  8. added this to the November 2020 milestone on Nov 19, 2020
  9. changed the title [-]Unnecessary searches triggered in remote[/-] [+]workspaceContains:*.txt starts a search through the workspace[/+] on Nov 19, 2020
  10. roblourens commented on Dec 14, 2020

    @roblourens
    MemberAuthor

    Local window:

    • *.txt incorrectly handled as **/*.txt

    UI extension in remote window:

    • anything incorrectly handled as **/anything

    There are many extensions using the second pattern, but I'm sure they would notice if it wasn't working in a local window, so I'm only concerned about the first pattern.

    In the top 1000 extensions, only 3 are affected

    In the few thousand beyond that, there are a few more that I have to look into. I've prepared the change, will push it soon.

    Two use */ and probably intended **/

    I think a lot of usages of workspaceContains:**/ are questionable in general. Will mention the perf impact and 5s limit in the release notes while we are on the topic.

  11. removed
    remote
    on Dec 31, 2020
  12. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Dec 31, 2020
  13. roblourens commented on Jan 30, 2021

    @roblourens
    MemberAuthor

    A summary here to link from the release notes:

    Here's the issue: This event is supposed to start a search in the user's workspace with the given glob pattern. A pattern like *.txt should activate the extension whenever the root of the workspace has a file matching *.txt, but it should not search the entire workspace. A pattern like **/*.txt should recursively search the entire workspace. We discovered that VS Code is incorrectly applying the ** pattern to every workspaceContains pattern that includes a *.

    If your extension depended on this behavior, you can easily get the old behavior back by prepending **/ to your workspaceContains pattern. However, you should think carefully about whether this is even necessary for your extension. It's usually sufficient to activate your extension only once the user actually opens a file of the type you are interested in (see the onLanguage activation event: https://code.visualstudio.com/api/references/activation-events). Using workspaceContains:**/... will start a search across the user's full workspace which may use a lot of CPU. And, if this search takes longer than 5s, the search will be canceled and your extension will be activated anyway. So please think carefully before using this pattern.

  14. locked and limited conversation to collaborators on Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buginsiders-releasedsearchverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions