zsh-workers
 help / color / mirror / code / Atom feed
* [PR] vcs_info-examples: optimize +vi-git-untracked() #76
@ 2021-06-27  6:09 Suraj N. Kurapati
  2021-06-27  9:13 ` Oliver Kiddle
  2021-06-27 13:03 ` Roman Perepelitsa
  0 siblings, 2 replies; 8+ messages in thread
From: Suraj N. Kurapati @ 2021-06-27  6:09 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Hello,

I have submitted pull-request #76 on the GitHub repo regarding:

           https://github.com/zsh-users/zsh/pull/76

Speed up the prompt on large and/or deep working directories by
stopping grep(1) as soon as it finds a single match, with `-q`.
Also, optimize the regular expression with an anchor and space.

Previously, +vi-git-untracked() waited for grep(1) to find all
matches of untracked files, redirecting them away to /dev/null,
before finally concluding that untracked files do indeed exist.

Thanks for your consideration.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-27  6:09 [PR] vcs_info-examples: optimize +vi-git-untracked() #76 Suraj N. Kurapati
@ 2021-06-27  9:13 ` Oliver Kiddle
  2021-06-27 10:04   ` Frank Terbeck
  2021-06-28 17:16   ` Suraj N. Kurapati
  2021-06-27 13:03 ` Roman Perepelitsa
  1 sibling, 2 replies; 8+ messages in thread
From: Oliver Kiddle @ 2021-06-27  9:13 UTC (permalink / raw)
  To: Suraj N. Kurapati; +Cc: zsh-workers

"Suraj N. Kurapati" wrote:
> I have submitted pull-request #76 on the GitHub repo regarding:
>
>            https://github.com/zsh-users/zsh/pull/76
>
> Speed up the prompt on large and/or deep working directories by
> stopping grep(1) as soon as it finds a single match, with `-q`.

The -q option to grep isn't strictly portable. It is certainly lacking
on Solaris. It is more reliable with egrep but that may not be faster.
It does seem to be there on Linux and the main BSDs so I don't know
whether we should still care about this.

Oliver


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-27  9:13 ` Oliver Kiddle
@ 2021-06-27 10:04   ` Frank Terbeck
  2021-06-28 17:16   ` Suraj N. Kurapati
  1 sibling, 0 replies; 8+ messages in thread
From: Frank Terbeck @ 2021-06-27 10:04 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Suraj N. Kurapati, zsh-workers

Oliver Kiddle wrote:
> "Suraj N. Kurapati" wrote:
[…]
>> Speed up the prompt on large and/or deep working directories by
>> stopping grep(1) as soon as it finds a single match, with `-q`.
>
> The -q option to grep isn't strictly portable. It is certainly lacking
> on Solaris. It is more reliable with egrep but that may not be faster.
> It does seem to be there on Linux and the main BSDs so I don't know
> whether we should still care about this.

I think  having this  in an example  is fine. We're  using "grep  -q" in
other places, too. Not that it matters  much, but ‘-q’ is part of SUSv3.
Maybe vendors should be asked to implement it therefore. :)

In any case,  I think its use  in examples of documentation  is fine. If
you're plagued with an implementation that doesn't implement -q, you get
to work around it.


Regards, Frank
-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-27  6:09 [PR] vcs_info-examples: optimize +vi-git-untracked() #76 Suraj N. Kurapati
  2021-06-27  9:13 ` Oliver Kiddle
@ 2021-06-27 13:03 ` Roman Perepelitsa
  2021-06-28 22:57   ` Suraj N. Kurapati
  1 sibling, 1 reply; 8+ messages in thread
From: Roman Perepelitsa @ 2021-06-27 13:03 UTC (permalink / raw)
  To: Suraj N. Kurapati; +Cc: Zsh hackers list

On Sun, Jun 27, 2021 at 8:07 AM Suraj N. Kurapati <sunaku@riseup.net> wrote:
> Speed up the prompt on large and/or deep working directories [...]

Do you have an estimate of the speedup? Numbers from at least one
repository on one machine would be useful to see.

Roman.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-27  9:13 ` Oliver Kiddle
  2021-06-27 10:04   ` Frank Terbeck
@ 2021-06-28 17:16   ` Suraj N. Kurapati
  1 sibling, 0 replies; 8+ messages in thread
From: Suraj N. Kurapati @ 2021-06-28 17:16 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

On Sun, 27 Jun 2021 11:13:53 +0200, Oliver Kiddle wrote:
> > Speed up the prompt on large and/or deep working directories by
> > stopping grep(1) as soon as it finds a single match, with `-q`.  
> 
> The -q option to grep isn't strictly portable. It is certainly lacking
> on Solaris.

POSIX (IEEE Std 1003.1-2017) says that grep(1) supports the `-q` option:

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html

Consequently, I'm surprised to hear that Solaris doesn't implement this.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-27 13:03 ` Roman Perepelitsa
@ 2021-06-28 22:57   ` Suraj N. Kurapati
  2021-06-29  7:16     ` Roman Perepelitsa
  2021-08-04  8:55     ` Roman Neuhauser
  0 siblings, 2 replies; 8+ messages in thread
From: Suraj N. Kurapati @ 2021-06-28 22:57 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 727 bytes --]

On Sun, 27 Jun 2021 15:03:17 +0200, Roman Perepelitsa wrote:
> On Sun, Jun 27, 2021 at 8:07 AM Suraj N. Kurapati wrote:
> > Speed up the prompt on large and/or deep working directories [...]  
> 
> Do you have an estimate of the speedup? Numbers from at least one
> repository on one machine would be useful to see.

I see a 4x speedup on a large Git-enabled home directory, as follows:

    $ time (git status --porcelain | wc -l)
    212
    0.01s user 0.02s system 0% cpu 9.021 total

    $ time (git status --porcelain | grep '??' &>/dev/null)
    0.01s user 0.02s system 0% cpu 12.294 total

    $ time (git status --porcelain | grep -q '^?? ' 2>/dev/null)
    0.01s user 0.01s system 0% cpu 3.097 total

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-28 22:57   ` Suraj N. Kurapati
@ 2021-06-29  7:16     ` Roman Perepelitsa
  2021-08-04  8:55     ` Roman Neuhauser
  1 sibling, 0 replies; 8+ messages in thread
From: Roman Perepelitsa @ 2021-06-29  7:16 UTC (permalink / raw)
  To: Suraj N. Kurapati; +Cc: Zsh hackers list

On Tue, Jun 29, 2021 at 12:55 AM Suraj N. Kurapati <sunaku@riseup.net> wrote:
>
> On Sun, 27 Jun 2021 15:03:17 +0200, Roman Perepelitsa wrote:
> > On Sun, Jun 27, 2021 at 8:07 AM Suraj N. Kurapati wrote:
> > > Speed up the prompt on large and/or deep working directories [...]
> >
> > Do you have an estimate of the speedup? Numbers from at least one
> > repository on one machine would be useful to see.
>
> I see a 4x speedup on a large Git-enabled home directory, as follows:
>
>     $ time (git status --porcelain | wc -l)
>     212
>     0.01s user 0.02s system 0% cpu 9.021 total
>
>     $ time (git status --porcelain | grep '??' &>/dev/null)
>     0.01s user 0.02s system 0% cpu 12.294 total
>
>     $ time (git status --porcelain | grep -q '^?? ' 2>/dev/null)
>     0.01s user 0.01s system 0% cpu 3.097 total

Thanks for posting these numbers.

So with your optimization it takes 3 seconds. That's quite a bit. And
I suppose that if you were to remove/add/ignore all untracked files,
it would go up to 9 seconds. Ouch!

Roman.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PR] vcs_info-examples: optimize +vi-git-untracked() #76
  2021-06-28 22:57   ` Suraj N. Kurapati
  2021-06-29  7:16     ` Roman Perepelitsa
@ 2021-08-04  8:55     ` Roman Neuhauser
  1 sibling, 0 replies; 8+ messages in thread
From: Roman Neuhauser @ 2021-08-04  8:55 UTC (permalink / raw)
  To: Suraj N. Kurapati; +Cc: Roman Perepelitsa, Zsh hackers list

# sunaku@riseup.net / 2021-06-28 15:57:36 -0700:
> On Sun, 27 Jun 2021 15:03:17 +0200, Roman Perepelitsa wrote:
> > On Sun, Jun 27, 2021 at 8:07 AM Suraj N. Kurapati wrote:
> > > Speed up the prompt on large and/or deep working directories [...]  
> > 
> > Do you have an estimate of the speedup? Numbers from at least one
> > repository on one machine would be useful to see.
> 
> I see a 4x speedup on a large Git-enabled home directory, as follows:
> 
>     $ time (git status --porcelain | wc -l)
>     212
>     0.01s user 0.02s system 0% cpu 9.021 total
> 
>     $ time (git status --porcelain | grep '??' &>/dev/null)
>     0.01s user 0.02s system 0% cpu 12.294 total
> 
>     $ time (git status --porcelain | grep -q '^?? ' 2>/dev/null)
>     0.01s user 0.01s system 0% cpu 3.097 total

this might be of interest (example code should be exemplary, no? :)

BACKGROUND REFRESH
  By default, git status will automatically refresh the index, updating
  the cached stat information from the working tree and writing out the
  result. Writing out the updated index is an optimization that isn’t
  strictly necessary (status computes the values for itself, but writing
  them out is just to save subsequent programs from repeating our
  computation). When status is run in the background, the lock held
  during the write may conflict with other simultaneous processes,
  causing them to fail. Scripts running status in the background should
  consider using git --no-optional-locks status (see git(1) for details).

-- 
roman


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-04  8:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27  6:09 [PR] vcs_info-examples: optimize +vi-git-untracked() #76 Suraj N. Kurapati
2021-06-27  9:13 ` Oliver Kiddle
2021-06-27 10:04   ` Frank Terbeck
2021-06-28 17:16   ` Suraj N. Kurapati
2021-06-27 13:03 ` Roman Perepelitsa
2021-06-28 22:57   ` Suraj N. Kurapati
2021-06-29  7:16     ` Roman Perepelitsa
2021-08-04  8:55     ` Roman Neuhauser

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).