Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/doc/component/Performance.markdown @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 Performance | |
2 =========== | |
3 | |
4 Parsing is computationally expensive task, to which the PHP language is not very well suited. | |
5 Nonetheless, there are a few things you can do to improve the performance of this library, which are | |
6 described in the following. | |
7 | |
8 Xdebug | |
9 ------ | |
10 | |
11 Running PHP with XDebug adds a lot of overhead, especially for code that performs many method calls. | |
12 Just by loading XDebug (without enabling profiling or other more intrusive XDebug features), you | |
13 can expect that code using PHP-Parser will be approximately *five times slower*. | |
14 | |
15 As such, you should make sure that XDebug is not loaded when using this library. Note that setting | |
16 the `xdebug.default_enable=0` ini option does *not* disable XDebug. The *only* way to disable | |
17 XDebug is to not load the extension in the first place. | |
18 | |
19 If you are building a command-line utility for use by developers (who often have XDebug enabled), | |
20 you may want to consider automatically restarting PHP with XDebug unloaded. The | |
21 [composer/xdebug-handler](https://github.com/composer/xdebug-handler) package can be used to do | |
22 this. | |
23 | |
24 If you do run with XDebug, you may need to increase the `xdebug.max_nesting_level` option to a | |
25 higher level, such as 3000. While the parser itself is recursion free, most other code working on | |
26 the AST uses recursion and will generate an error if the value of this option is too low. | |
27 | |
28 Assertions | |
29 ---------- | |
30 | |
31 Assertions should be disabled in a production context by setting `zend.assertions=-1` (or | |
32 `zend.assertions=0` if set at runtime). The library currently doesn't make heavy use of assertions, | |
33 but they are used in an increasing number of places. | |
34 | |
35 Object reuse | |
36 ------------ | |
37 | |
38 Many objects in this project are designed for reuse. For example, one `Parser` object can be used to | |
39 parse multiple files. | |
40 | |
41 When possible, objects should be reused rather than being newly instantiated for every use. Some | |
42 objects have expensive initialization procedures, which will be unnecessarily repeated if the object | |
43 is not reused. (Currently two objects with particularly expensive setup are lexers and pretty | |
44 printers, though the details might change between versions of this library.) | |
45 | |
46 Garbage collection | |
47 ------------------ | |
48 | |
49 A limitation in PHP's cyclic garbage collector may lead to major performance degradation when the | |
50 active working set exceeds 10000 objects (or arrays). Especially when parsing very large files this | |
51 limit is significantly exceeded and PHP will spend the majority of time performing unnecessary | |
52 garbage collection attempts. | |
53 | |
54 Without GC, parsing time is roughly linear in the input size. With GC, this degenerates to quadratic | |
55 runtime for large files. While the specifics may differ, as a rough guideline you may expect a 2.5x | |
56 GC overhead for 500KB files and a 5x overhead for 1MB files. | |
57 | |
58 Because this a limitation in PHP's implementation, there is no easy way to work around this. If | |
59 possible, you should avoid parsing very large files, as they will impact overall execution time | |
60 disproportionally (and are usually generated anyway). | |
61 | |
62 Of course, you can also try to (temporarily) disable GC. By design the AST generated by PHP-Parser | |
63 is cycle-free, so the AST itself will never cause leaks with GC disabled. However, other code | |
64 (including for example the parser object itself) may hold cycles, so disabling of GC should be | |
65 approached with care. |