Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve memory efficiency#18932

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:2.7fromdword-design:console-output-memory-efficiency
Jun 3, 2016
Merged

Improve memory efficiency#18932

nicolas-grekas merged 1 commit intosymfony:2.7fromdword-design:console-output-memory-efficiency
Jun 3, 2016

Conversation

@dword-design
Copy link

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

This avoids concatenating$message andPHP_EOL (if necessary) as a new value, greatly improving memory efficiency for large$messages.

This avoids concatenating `$message` and `PHP_EOL` (if necessary) as a new value, greatly improving memory efficiency for large `$message`s.
@dword-design
Copy link
Author

This is my first pull request, please don't hurt me :)

mpdude reacted with heart emoji

protectedfunctiondoWrite($message,$newline)
{
if (false === @fwrite($this->stream,$message.($newline?PHP_EOL :''))) {
if (false === @fwrite($this->stream,$message) ||($newline&& (false === @fwrite($this->stream,PHP_EOL)))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

what about:

if (false === @fwrite($this->stream,$message)) {// should never happenthrownew \RuntimeException('Unable to write output.');        }if ($newline) {            @fwrite($this->stream,PHP_EOL);        }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In this case no Exception would be thrown if something goes wrong with writing PHP_EOL.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

yep, which won't happen if the first fwrite already succedeed IMHO

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could be but what speaks against the safe solution?

@OskarStark
Copy link
Contributor

greatly improving memory efficiency

can you show some statistics about that?

@javiereguiluz
Copy link
Member

@Dword123 congrats on your first pull request and thanks for contributing to Symfony!

The kind of improvement that you propose here is always tricky for us. This affects the console output stream, which is something that it's not used frequently or on every request. That's why most of the times these improvements don't provide enough gains to be worthy. So let's see what other contributors think about this.

OskarStark reacted with thumbs up emoji

@mpdude
Copy link
Contributor

We're using symfony/console over athttps://github.com/webfactory/slimdump, a tool that makes SQL dumps tostdout somewhat similar to whatmysqldump does.

In that case, themessage can be a hex-encoded BLOB (files or the like) and a few dozen MB in size.

If the newline is added to the string before being written, PHP has to allocate additional memory about the size of$message to store the new resulting value.

Asked the other way round: What problem could this change cause?

javiereguiluz reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

👍

@nicolas-grekas
Copy link
Member

Thank you @Dword123.

@nicolas-grekasnicolas-grekas merged commitc1df9f2 intosymfony:2.7Jun 3, 2016
nicolas-grekas added a commit that referenced this pull requestJun 3, 2016
This PR was merged into the 2.7 branch.Discussion----------Improve memory efficiency| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |This avoids concatenating `$message` and `PHP_EOL` (if necessary) as a new value, greatly improving memory efficiency for large `$message`s.Commits-------c1df9f2 Improve memory efficiency
mpdude added a commit to webfactory/slimdump that referenced this pull requestJun 3, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@dword-design@OskarStark@javiereguiluz@mpdude@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp