Commit 0606d02
gh-151788: Speed up http.server directory listing by using os.scandir
SimpleHTTPRequestHandler.list_directory() called os.path.isdir() and
os.path.islink() for every entry, issuing two stat-family syscalls per
file. This is wasted work on any filesystem and dominates listing time
for large directories; on network filesystems such as NFS, where each
call is a round-trip, it becomes severe.
Use os.scandir(), whose DirEntry objects report the type from the
directory read itself (d_type / READDIRPLUS), eliminating the per-entry
stats in the common case and never doing more work than before.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent aa5b164 commit 0606d02
2 files changed
Lines changed: 13 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
875 | | - | |
| 875 | + | |
| 876 | + | |
876 | 877 | | |
877 | 878 | | |
878 | 879 | | |
879 | 880 | | |
880 | 881 | | |
881 | | - | |
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
903 | | - | |
| 902 | + | |
| 903 | + | |
904 | 904 | | |
905 | | - | |
906 | | - | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
907 | 909 | | |
908 | 910 | | |
909 | | - | |
| 911 | + | |
910 | 912 | | |
911 | 913 | | |
912 | 914 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments