TysonAndre / phan

Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.
Other
0 stars 0 forks source link

Investigate usage of asynchronous I/O (file_get_contents) to speed up parse phase #59

Open TysonAndre opened 7 years ago

TysonAndre commented 7 years ago

It seems like Phan isn't using 100% of it's CPU (saw 40%?) in the parse phase (but uses more in the analysis phase), probably due to spending a long time blocked on reading the file contents into memory.

http://amphp.org/amp/promises/ and https://github.com/amphp/file (Still in alpha) seem like they may be used to asynchronously read files.

Possible pseudocode (Not familiar enough with AMPHP to know if this will work, or if there's a cleaner way)

def fileReader(string[] fileNameList):
    # yields a list of file contents and the corresponding file names.
    BUF_SIZE = 4 # Simultaneously attempt to read at most this many files at a time.
    filePromiseBuf = new Queue()
    for fileName in fileList:
         filePromise = Amp\File\read(fileName)
         filePromiseBuf.push_back(filePromise)
         if filePromise.length() >= BUF_SIZE()
               yield filePromise.pop_front().wait() # missing error handling and file name
    while not filePromiseBuf.empty():
         yield filePromise.pop_front().wait()