<commit_before>******************
Performance tricks
******************

If you use ``php-v8`` extension for short-lived tasks or you have your :class:`Context` likely to be long-living enough
so that ``V8`` runtime optimizations won't have significant impact, you can still improve your performance.

Important note: all caching techniques are V8 version-specific and platform specific, some caches won't even work on
different CPU with different instructions set, you have to test following techniques for your environment and
infrastructure and be ready to fallback to raw, cache-less flow.


Let's say you have an typical Hello, world! script:

.. code:: php

    <?php declare(strict_types=1);

    use V8\{
        Isolate,
        Context,
        StringValue,
        Script,
    };

    $script_source_string = "function say() { return 'Hello' + ', World!'}; say()";<commit_msg>Clarify docs regards perf optimizations [skip ci]<commit_after>******************
Performance tricks
******************

If you:

 * use ``php-v8`` extension for short-lived tasks or
 * you have your :class:`Context` short-lived

it is likely that you won't be able benefit from ``V8`` runtime optimizations.
However, you can still improve your performance.

*Important note*: all caching techniques are V8 version-specific and platform specific, some caches won't even work on
different CPU with different instructions set, you have to test following techniques for your environment and
infrastructure and be ready to fallback to raw, cache-less flow.


Let's say you have an typical Hello, world! script:

.. code:: php

    <?php declare(strict_types=1);

    use V8\{
        Isolate,
        Context,
        StringValue,
        Script,
    };

    $script_source_string = "function say() { return 'Hello' + ', World!'}; say()";
{'fraction_non_alphanumeric': 0.12081274025260846, 'fraction_numerical': 0.0054914881933003845, 'mean_word_length': 3.937669376693767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '359065', 'n_tokens_mistral': 489, 'n_tokens_neox': 460, 'n_words': 216}