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

[VarDumper] Keep and reuse array stubs in memory#23683

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
fabpot merged 1 commit intosymfony:3.3fromnicolas-grekas:var-perf
Jul 28, 2017

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedJul 26, 2017
edited
Loading

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

(to be reviewedignoring whitespaces)

As highlighted by@vtsykun in#23620, the patch in#23644 improves performance but increases the memory usage.

The issue is that even a smallarray($k => $v) consumes more memory than anew Stub().
That's a shame, but since our small arrays have a low variety, we can keep them in a cache and leverage php's COW mechanism to reduce memory. Effectively, this creates a memory leak. But the leak is upper bounded by the data you had already in memory, since that's what is cloned. Looking at the numbers, it looks worth it:

3.3.5+#23644+this PR
Wall Time39.4s26.1s18.6s 17.3s
Memory391MB539MB217MB 216MB

https://blackfire.io/profiles/compare/846b58bc-7863-4502-9ca2-f82eebd4173f/graph

vtsykun, mvhirsch, AlexBDev, mickaelandrieu, ogizanagi, and TomasVotruba reacted with thumbs up emoji
@nicolas-grekasnicolas-grekas added this to the3.3 milestoneJul 26, 2017
@nicolas-grekasnicolas-grekas changed the title[DI] Keep and reuse array stubs in memory[VarDumper] Keep and reuse array stubs in memoryJul 26, 2017
@nicolas-grekas
Copy link
MemberAuthor

On a smaller profile with GC disabled to be sure we don't compare just GC's time:
https://blackfire.io/profiles/compare/53798f9a-e2ab-42b4-94b4-a564f15814d5/graph
still -32% in memory, and -5% in wall time.

Anotherhttps://blackfire.io achievement! :)

@Koc
Copy link
Contributor

Koc commentedJul 26, 2017

18.6s is too much anyway

@nicolas-grekas
Copy link
MemberAuthor

@Koc see#23659 for the core reason why this test page is slow.

vtsykun referenced this pull request in oroinc/platformJul 26, 2017
…1598)- added local cache for a logger collector- overwrite symfony`s data_collector.logger class- added tests
// or null if the original value is used directly

if (!self::$hashMask) {
self::$gid =uniqid(mt_rand(),true);// Unique string used to detect the special $GLOBALS variable
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why this doesn't just userandom_bytes? (unrelated to the actual change)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Just history, since there is a version of this code that works on PHP 5.3 and the provided uniqueness is good enough

Copy link
Contributor

Choose a reason for hiding this comment

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

PHP 5.3 isnot a problem, but if the provided uniqueness is good enough, that's fine, too. Didn't look what it's used for, it's just theuniqid that auto-triggered me writing a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's just a unique string, why not just use a global counter with$counter = "a"; $counter++? This ensures uniqueness in the process and avoids two function calls there.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

it's a unique string that needs to be collision free with the $GLOBALS arrays, where users can put any keys. global uniqueness is important

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to, you can just read the current value with(function () { var_dump(self::$gid); })->bindTo(null, VarCloner::class)();, but I think I gave enough input, don't care to discuss it further.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

you can just read the current value with [...]

true, fixed now :)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hum, not quite, I forgot aboutReflectionMethod::getStaticVariables() :)

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasJul 27, 2017
edited
Loading

Choose a reason for hiding this comment

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

now replaced by a local variable, using spl_object_hash instead of uniqid

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, there's no real way to prevent that. It's not public API, if people break it, they deserve what they get.

}

$queue[$i] =$vals;
unset($indexedArrays[$i]);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

another µ-optim: unsetting scalars from arrays does not free memory, but takes CPU, better not doing it

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Why does it not free memory?

Copy link
Member

Choose a reason for hiding this comment

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

because they are still referenced elsewhere (in the variable being cloned)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

well, not exactly for this reason in this case: it's because PHP allocates arrays as they grow, and never frees the allocated memory when they shrink. I think this article might explain it:http://jpauli.github.io/2016/04/08/hashtables.html

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

So, when the table is full and when we empty it, the memory usage doesn't move at all (modulo noise). When we finished unset()ing every value, we end having a hashtable which arData is 32768 slots all full of UNDEF zvals.

@nicolas-grekasnicolas-grekasforce-pushed thevar-perf branch 2 times, most recently fromc1dcf06 tod63887bCompareJuly 27, 2017 12:20
$maxString =$this->maxString;
$cookie = (object)array();// Unique object used to detect hard references
$gid =uniqid(mt_rand(),true);// Unique string used to detect the special $GLOBALS variable
$gid =\spl_object_hash($cookie);// Unique string used to detect the special $GLOBALS variable
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if that's relevant in this context, butspl_object_hash does not guarantee that it returns a unique value. The value can be reused when objects are reclaimed. And we did hit that limitation in the past (and Doctrine as well), so that's not just theoretical.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

you're right, back to my first version, it was fine :)

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit92fa55d intosymfony:3.3Jul 28, 2017
fabpot added a commit that referenced this pull requestJul 28, 2017
…grekas)This PR was merged into the 3.3 branch.Discussion----------[VarDumper] Keep and reuse array stubs in memory| Q             | A| ------------- | ---| Branch?       | 3.3| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -(to be reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/23683/files?w=1))As highlighted by@vtsykun in#23620, the patch in#23644 improves performance but increases the memory usage.The issue is that even a small `array($k => $v)` consumes more memory than a `new Stub()`.That's a shame, but since our small arrays have a low variety, we can keep them in a cache and leverage php's COW mechanism to reduce memory. Effectively, this creates a memory leak. But the leak is upper bounded by the data you had already in memory, since that's what is cloned. Looking at the numbers, it looks worth it:|   | 3.3.5 | +#23644 | +this PR| --- | --- | --- | ---| Wall Time    | 39.4s | 26.1s | ~~18.6s~~ 17.3s| Memory       | 391MB | 539MB | ~~217MB~~ 216MBhttps://blackfire.io/profiles/compare/846b58bc-7863-4502-9ca2-f82eebd4173f/graphCommits-------92fa55d [VarDumper] Keep and reuse array stubs in memory
@nicolas-grekasnicolas-grekas deleted the var-perf branchJuly 28, 2017 16:42
@fabpotfabpot mentioned this pull requestAug 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@kelunikkelunikkelunik left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

6 participants

@nicolas-grekas@Koc@fabpot@stof@kelunik@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp