Closed Bug 1535010 Opened 4 years ago Closed 3 years ago

GMPDiskStorage.cpp and GMPServiceParent.cpp do unnecessary I/O syscalls to create directories during startup


(Core :: Audio/Video: GMP, enhancement, P2)




Tracking Status
firefox68 --- fixed


(Reporter: florian, Assigned: florian)



(Keywords: perf, Whiteboard: [fxperf:p1])


(1 file)

The behavior of nsLocalFile::Create(a/b/c) is to attempt to create the final directory a/b/c first, and if that fails because the previous path components don't exist yet, to create them recursively and then create the final directory again.

The current GMP code, when it wants to use something in a directory a/b/c is to first call nsLocalFile->Create(a), then nsLocalFile->Create(a/b) and then nsLocalFile->Create(a/b/c).

This does useless main thread I/O system calls whenever the directories already exist.

Another bad pattern is to call nsLocalFile->Exists (which does main thread I/O) before doing something that will fail cleanly if the file or directory doesn't exist.
if (file.exists()) {
} else {
create file...
is inefficient. We should read the file without checking if it exists, and if that fails check the error code to see if the failure is because the file didn't exist.

The 2 cases that I really care about are
<user profile>\gmp
<user profile>\gmp\WINNT_x86-msvc
which are done unconditionally on the main thread during startup before first paint. The first of these 2 calls is obviously unnecessary. The second one is unnecessary too because when we do use that gmp/$platform folder, it's always to create a subfolder, or to remove the folder (I inspected all the callers I could find).

The patch I'm going to attach cleans up bad patterns in a few other cases where it was clear from code inspection. I refrained from doing any change that requires a real underestanding of the code, but I saw a few other places with Exists calls that didn't seem required (I don't know the code enough to know if they happen on the main thread or off main thread; if it's off main thread it doesn't matter much).

Note: I'm fairly confident that these changes are correct, but I don't know how to exercise this code, so it would be good if you could either test it yourself locally when reviewing, or suggest which tests to run on try, or both; thanks!

Priority: -- → P2

Adding a needinfo in case you missed the phabricator review request.

Flags: needinfo?(cpearce)
Blocks: 1522877

(In reply to Florian Quèze [:florian] from comment #3)

Adding a needinfo in case you missed the phabricator review request.

r+, I did in fact miss this review request. Sorry!

Flags: needinfo?(cpearce)
Pushed by
avoid unnecessary gmp directory creations during startup, r=cpearce.
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
You need to log in before you can comment on or make changes to this bug.