On 2025-01-19 05:56, Devste Devste via Cygwin wrote:
strace -o strace.log dirname -- /some/path/here
There are 2 points that could make it significantly faster and
shouldn't be too hard to implement?

Criticisms as expected to be accompanied by code and all Patches are Thoughtfully Considered (PTC - see https://cygwin.com/acronyms/) - git format-patch/send-email against repo main branch to cygwin-patches@... ML.

All contributors are volunteers working when they have spare time available.

1) A significant amount of time is spent on user auth (as seen in
various github issues the infamous /etc/passwd nsswitch.conf fix)
Wouldn't it be possible to just reuse the auth data from the current
shell for the subshell, e.g. for
basename -- $(dirname -- /some/path/here)

Some of this is done for each child in a Cygwin process tree, and for all Cygwin processes if you run cygserver.
You can also decide to limit what sources should be used in nsswitch.conf.

2) why are unix/dos path conversions of environment variables not
cached? A significant amount of time (15-30%, depending on the number
of environment variables) is spent on the conversion for every
invocation.
However, this would be extremely simple to cache and reusable even on
completely unrelated subshells.
cache key = original path
cache value = converted value
e.g.

```
    44   12839 [main] dirname 16929 mount_info::conv_to_posix_path:
conv_to_posix_path (C:\Users\User123\bin, 0x10000100, no-add-slash)
    44   12883 [main] dirname 16929 normalize_win32_path:
C:\Users\User123\bin = normalize_win32_path (C:\Users\User123\bin)
    44   12927 [main] dirname 16929 mount_info::conv_to_posix_path:
mount[0] .. checking / -> C:\Program Files\Git
    44   12971 [main] dirname 16929 mount_info::conv_to_posix_path:
mount[1] .. checking /bin -> C:\Program Files\Git\usr\bin
    44   13015 [main] dirname 16929 mount_info::conv_to_posix_path:
mount[2] .. checking /tmp -> C:\Users\User123\AppData\Local\Temp
    44   13059 [main] dirname 16929 mount_info::conv_to_posix_path:
/c/Users/User123/bin = conv_to_posix_path (C:\Users\User123\bin)
```
could be cached with key
C:\Users\User123\bin
and value
/c/Users/User123/bin
at least for the current process (e.g. a bash script and it's
children) without risking any noticeable outdated cache issues
(probably even longer, however we want to keep it simple and don't
want to worry about cache invalidation too much)

Any process can change the environment, so contents can not be assumed, and everything has to be rechecked each time.
It is probably quicker (44µs) to check for paths and convert.

Drop all the Windows paths and variables from your Cygwin environment, unless you intend to run Windows programs from there, and you will not have so much overhead.

For a cache, you would want to key from the env var name, have a path flag, and keep Windows and Cygwin alternatives, but that only helps if you have child processes where the environment stays the same, so the penalty should be paid in any children.

--
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                -- Antoine de Saint-Exupéry

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to