- 
                Notifications
    
You must be signed in to change notification settings  - Fork 18.4k
 
Description
Proposal: net/http: optimize http.Dir when files are not modified and add GODEBUG to preserve old behavior
Author(s): @qiualidongfeng
Last updated: 2023-11-19
Abstract
If there are no errors, http.Dir calls os.Open once every time Open is called. If the file has not changed, performance can be improved by reducing system calls by caching *os.File and []byte read from *os.File.
Background
Background as described above.
Proposals to optimize http.Dir.
Proposal
http.Dir.Open When the file modification time does not change, use the cached *os.FIle and []byte.
Add the GODEBUG environment variable httpdircache, go1.23 defaults to 1, enabling the behavior after the proposal implementation. Setting the value to 0 restores the previous behavior.
Rationale
1, directly change the behavior, when the file modification time is unchanged but the content changes, backward incompatible.
2, Third-party libraries, such as https://github.com/qiulaidongfeng/cachefs , This is a prototype written in a third-party library before sending CL to the standard library. The advantage is that it can be used less than go1.23, and the disadvantage is that the code needs to be manually modified to use.
Compatibility
100% backward compatibility with godebug=httpdircache=0.
Implementation
I will send CL to implement the proposal, which is too close to go1.22 code freezing, so this proposal is for go1.23.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status