|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-09-13 00:02 UTC] rasmus@php.net
-Status: Open
+Status: Suspended
[2013-09-13 00:02 UTC] rasmus@php.net
[2013-09-18 13:24 UTC] gopalv@php.net
[2013-09-18 15:03 UTC] askalski at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 10:00:01 2025 UTC |
Description: ------------ I'm running into an issue with APC (unnecessarily?) caching a copy of the current values of inherited static variables when caching opcodes for a derived class. This causes exceessive memory use, both in the APC cache itself, and by the scripts which are later loaded from cache. (In the scenario I'm troubleshooting, there is a widely-used base class which keeps up to ~1MB of data in a static array, so the memory usage issue is particularly severe, because that 1MB gets multiplied many times.) The cause seems to be copying around the entire 'default_static_members_table' of the class. Would it be possible/safe to exclude copying array slots of inherited static members, and copy only those members which belong to the derived class itself? Test script: --------------- <?php /* 1.php */ if (isset($_GET['clear'])) { echo "Clearing opcode cache.\n"; apc_clear_cache('system'); exit; } class A { public static $var; } if (isset($_GET['bytes'])) A::$var = str_repeat('x', (int) $_GET['bytes']); $usage0 = memory_get_usage(); echo "Memory usage before including subclasses: ", ($usage0 = memory_get_usage()), "\n"; require_once("2.php"); $diff = ($usage = memory_get_usage()) - $usage0; echo "Memory usage after including subclasses: $usage (difference: $diff)\n"; ?> <?php /* 2.php */ class B1 extends A { } class B2 extends A { } class B3 extends A { } class B4 extends A { } class B5 extends A { } class B6 extends A { } class B7 extends A { } class B8 extends A { } ?> Expected result: ---------------- The change in memory usage before/after including the derived classes file (2.php) should be small. $ curl http://$HOSTNAME/1.php?clear Clearing opcode cache. $ curl http://$HOSTNAME/1.php?bytes=5444333 Memory usage before including subclasses: 5684416 Memory usage after including subclasses: 5692224 (difference: 7808) $ curl http://$HOSTNAME/1.php?bytes=1 Memory usage before including subclasses: 232696 Memory usage after including subclasses: 242024 (difference: 9328) ^^^^^^ ^^^^ Actual result: -------------- The change in memory usage is large, because APC is storing a copy of the str_repeat with each cached derived class. $ curl http://$HOSTNAME/1.php?clear Clearing opcode cache. $ curl http://$HOSTNAME/1.php?bytes=5444333 Memory usage before including subclasses: 5684032 Memory usage after including subclasses: 5691840 (difference: 7808) $ curl http://$HOSTNAME/1.php?bytes=1 Memory usage before including subclasses: 233080 Memory usage after including subclasses: 43796968 (difference: 43563888) ^^^^^^^^ ^^^^^^^^