-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve virion_infect performance #239
base: beta
Are you sure you want to change the base?
Conversation
unlink($this->path); | ||
$this->path .= DIRECTORY_SEPARATOR; | ||
mkdir($this->path, 0666); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this error-safe. Consider race conditions of path being used by another process between unlink() and mkdir().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you have the chance of two virions building in the same directory and mixing up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a way to do this without either throwing an exception (if(!mkdir()) throw $e
) or a possibly long-lasting while(!mkdir()) sleep()
loop. I thought of going with if(!is_dir()) mkdir()
because the only other mkdir call in poggit/poggit goes with that approach, any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose another tempnam if the directory creation failed. Only run the subsequent code if you are the one who created this directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Muqsit you had a chance to do this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not confident that the logic is still correct... If $this->path
doesn't already exist, something might have gone wrong, and you should choose another tempnam. If $this->path
is already a directory, this also means something is wrong, and you should also choose another tempnam.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I do understand the issue, I unfortunately don't have much knowledge in this field and would prefer someone else take over this task as deleting the wrong directory could lead to unperceivable results, possibly even out of the realms of this program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about sticking getmypid()
on the end of the folder name?
unlink($this->path); | ||
$this->path .= DIRECTORY_SEPARATOR; | ||
mkdir($this->path, 0666); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not confident that the logic is still correct... If $this->path
doesn't already exist, something might have gone wrong, and you should choose another tempnam. If $this->path
is already a directory, this also means something is wrong, and you should also choose another tempnam.
I think the temp dir thing is rare enough to matter. @JaxkDev any other comments? |
I dont touch virions lol |
Are you sure it is O(n!)? It just sounds like O(n^2) to me. |
Yeah. Previously, for each file that was inserted in |
No, that's O(n^2). To be precise, it is. 1 + 2 + ... + n = n(n+1)/2. O(n!) multiplies them together instead of adding. That would take centuries for something like PocketMine. |
Significantly improves performance of
virion_infect
by placing changed files in a temporary directory and callingPhar::buildFromDirectory($temp_dir_path)
. This avoids repackaging phar for every changed file (repackaging happens only during thePhar::buildFromDirectory
call).The complexity is reduced from
O(n^2)
all the way toO(n)
wheren
is the number of files being packaged into.phar
.