Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Nushell integration adds a significant delay before each prompt #2208

Open
1 task done
Tracked by #8
WieeRd opened this issue Jun 29, 2024 · 2 comments
Open
1 task done
Tracked by #8

[Bug]: Nushell integration adds a significant delay before each prompt #2208

WieeRd opened this issue Jun 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@WieeRd
Copy link

WieeRd commented Jun 29, 2024

What did you expect to happen?

Atuin integration with Bash/Zsh did not slow down the shell.
I expected the same with Nushell.

What happened?

There is a noticeable delay after the invoked command's completion and before the new shell prompt shows up.
Even when running a very simple command like ls which takes less than a millisecond.

~
❯ atuin history list | lines | length
8795

~
❯ timeit do { atuin history end --exit 0 (atuin history start -- ls) }
243ms 217µs 340ns

~
❯ mv ~/.local/share/atuin/ ~/.local/share/atuin.backup

~
❯ atuin history list | lines | length
1

~
❯ timeit do { atuin history end --exit 0 (atuin history start -- ls) }
20ms 317µs 702ns

I have 8.8k history records and atuin history start + atuin history end pair take around 240ms.
After nuking the DB at ~/.local/share/atuin that time is reduced to 20ms and the delay is no longer noticeable.

The prompt was instantaneous regardless of the history size on the other shells (Bash/Zsh).
So I assume this has to do with Nushell integration specifically.

Atuin doctor output

{
  "atuin": {
    "version": "18.3.0",
    "sync": null,
    "sqlite_version": "3.44.0"
  },
  "shell": {
    "name": "nu",
    "default": "nu",
    "plugins": [
      "atuin"
    ],
    "preexec": "built-in"
  },
  "system": {
    "os": "Arch Linux",
    "arch": "x86_64",
    "version": "unknown",
    "disks": [
      {
        "name": "/dev/nvme0n1p3",
        "filesystem": "btrfs"
      },
      {
        "name": "/dev/nvme0n1p3",
        "filesystem": "btrfs"
      },
      {
        "name": "/dev/nvme0n1p3",
        "filesystem": "btrfs"
      },
      {
        "name": "/dev/nvme0n1p3",
        "filesystem": "btrfs"
      },
      {
        "name": "/dev/nvme0n1p3",
        "filesystem": "btrfs"
      },
      {
        "name": "/dev/nvme0n1p2",
        "filesystem": "ext4"
      },
      {
        "name": "/dev/nvme0n1p1",
        "filesystem": "vfat"
      }
    ]
  }
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@WieeRd WieeRd added the bug Something isn't working label Jun 29, 2024
@WieeRd WieeRd changed the title [Bug]: Nushell integration adds a significantly delay before each prompt [Bug]: Nushell integration adds a significant delay before each prompt Jul 31, 2024
@WieeRd
Copy link
Author

WieeRd commented Jul 31, 2024

The problem is that Nushell hooks are blocking.

The vast majority of the delay comes from querying the SQLite database, which is not affected by the shell I'm using. The difference is that while other integration scripts for other shells seem to hide this delay from the user by running history start/stop in the background, Nushell has to wait the whole time until the query completes.

Nushell does not support background task or job control yet.

Instead, it recommends the use of 3rd party job control tools like pueue.

So what we can do right now on the Atuin's side, before the official support for job control, is to detect if pueue is available and run the history commands through it. Falling back to the blocking call if it's unavailable and potentially printing out warnings about the delay.

@WieeRd
Copy link
Author

WieeRd commented Aug 17, 2024

Enabling the experiment Atuin daemon significantly cut down the delay, as the hook commands can just ask the daemon to do the work and be on their way without waiting for the query to finish.

Until Nushell implements job control this would be the best method to mitigate this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant