Skip to content

Add specialized handler for checking if identical to string #4972

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TysonAndre
Copy link
Contributor

This has a large performance benefit for the below snippet (0.64s vs 0.94s),
and a small benefit for $alwaysStr == 'notnumeric'/$s = 'other'
(for 1000 runs of test('test'))

  • If the literal is non-numeric and the variable is a string,
    == behaves identically to ===, so reuse the opcode.

This is similar to what was suggested in #4900

  • Avoiding types with __destruct or notices simplifies the specialized
    implementation and avoids expensive exception handling.
  • TMPVARCV doesn't support FREE_OP1() - use TMPVAR|CV instead.
function test(string $s) : int {
    $total = 0;
    for ($i = 0; $i < 100000; $i++) {
        if ($s === "first") {
            $total++;
            $s = null;
        }
    }
    return $total;
}

This has a large performance benefit for the below snippet (0.64s vs 0.94s),
and a small benefit for `$alwaysStr == 'notnumeric'`/`$s = 'other'`
(for 1000 runs of test('test'))

- If the literal is non-numeric and the variable is a string,
  `==` behaves identically to `===`, so reuse the opcode.

This is similar to what was suggested in php#4900

- Avoiding types with __destruct or notices simplifies the specialized
  implementation and avoids expensive exception handling.
- TMPVARCV doesn't support FREE_OP1() - use TMPVAR|CV instead.

```
function test(string $s) : int {
    $total = 0;
    for ($i = 0; $i < 100000; $i++) {
        if ($s === "first") {
            $total++;
            $s = null;
        }
    }
    return $total;
}
```
@TysonAndre TysonAndre force-pushed the identical-string-spec branch from 92705cf to e6f8df2 Compare August 9, 2020 15:22
@TysonAndre TysonAndre requested a review from iluuu1994 as a code owner October 7, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants