Skip to content

ESQL: Speed up TO_IP #126338

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

Merged
merged 4 commits into from
Apr 7, 2025
Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Apr 4, 2025

Speed up the TO_IP method by converting directly from utf-8 encoded strings to the ip encoding. Previously we did:

utf-8 -> String -> INetAddress -> ip encoding

In a step towards solving #125460 this creates three IP parsing functions, one the rejects leading zeros, one that interprets leading zeros as decimal numbers, and one the interprets leading zeros as octal numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into TO_IP because that's the behavior it had before.

Here is the performance:

Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op

So this is roughly 45% faster than what we had.

Speed up the TO_IP method by converting directly from utf-8 encoded
strings to the ip encoding. Previously we did:
```
utf-8 -> String -> INetAddress -> ip encoding
```

In a step towards solving elastic#125460 this creates three IP parsing
functions, one the rejects leading zeros, one that interprets leading
zeros as decimal numbers, and one the interprets leading zeros as octal
numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into `TO_IP` because
that's the behavior it had before.

Here is the performance:
```
Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op
```

So this is roughly 45% faster than what we had.
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Apr 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @nik9000, I've created a changelog YAML for you.

@nik9000 nik9000 added the auto-backport Automatically create backport pull requests when merged label Apr 7, 2025
@nik9000 nik9000 merged commit 7e1e45e into elastic:main Apr 7, 2025
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.0 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 126338

@nik9000
Copy link
Member Author

nik9000 commented Apr 7, 2025

Note so we don't lose it: There's some talk about use SIMD to parse ipv4 addresses. They fit in a single SIMD register after all. The reading I did doesn't discuss leading zeros so that'd be fun! Anyway, I wanted something I could backport easily and our ways of directly accessing SIMD code didn't look super easy to backport at the moment, so I left it for later.

@nik9000
Copy link
Member Author

nik9000 commented Apr 7, 2025

Commit could not be cherrypicked due to conflicts

Betrayal!

nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 7, 2025
Speed up the TO_IP method by converting directly from utf-8 encoded
strings to the ip encoding. Previously we did:
```
utf-8 -> String -> INetAddress -> ip encoding
```

In a step towards solving elastic#125460 this creates three IP parsing
functions, one the rejects leading zeros, one that interprets leading
zeros as decimal numbers, and one the interprets leading zeros as octal
numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into `TO_IP` because
that's the behavior it had before.

Here is the performance:
```
Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op
```

So this is roughly 45% faster than what we had.

This includes a big chunk of elastic#124676 - but not the behavior change -
just the code that allowed it.
@nik9000
Copy link
Member Author

nik9000 commented Apr 7, 2025

9.0: #126431
8.x: #126433

nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 7, 2025
Speed up the TO_IP method by converting directly from utf-8 encoded
strings to the ip encoding. Previously we did:
```
utf-8 -> String -> INetAddress -> ip encoding
```

In a step towards solving elastic#125460 this creates three IP parsing
functions, one the rejects leading zeros, one that interprets leading
zeros as decimal numbers, and one the interprets leading zeros as octal
numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into `TO_IP` because
that's the behavior it had before.

Here is the performance:
```
Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op
```

So this is roughly 45% faster than what we had.

This includes a big chunk of elastic#124676 - but not the behavior change -
just the code that allowed it.
elasticsearchmachine pushed a commit that referenced this pull request Apr 7, 2025
Speed up the TO_IP method by converting directly from utf-8 encoded
strings to the ip encoding. Previously we did:
```
utf-8 -> String -> INetAddress -> ip encoding
```

In a step towards solving #125460 this creates three IP parsing
functions, one the rejects leading zeros, one that interprets leading
zeros as decimal numbers, and one the interprets leading zeros as octal
numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into `TO_IP` because
that's the behavior it had before.

Here is the performance:
```
Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op
```

So this is roughly 45% faster than what we had.

This includes a big chunk of #124676 - but not the behavior change -
just the code that allowed it.
elasticsearchmachine pushed a commit that referenced this pull request Apr 7, 2025
Speed up the TO_IP method by converting directly from utf-8 encoded
strings to the ip encoding. Previously we did:
```
utf-8 -> String -> INetAddress -> ip encoding
```

In a step towards solving #125460 this creates three IP parsing
functions, one the rejects leading zeros, one that interprets leading
zeros as decimal numbers, and one the interprets leading zeros as octal
numbers. IPs have historically been parsed in all three of those ways.

This plugs the "rejects leading zeros" parser into `TO_IP` because
that's the behavior it had before.

Here is the performance:
```
Benchmark               Score    Error  Units
leadingZerosAreDecimal  14.007 ± 0.093  ns/op
leadingZerosAreOctal    15.020 ± 0.373  ns/op
leadingZerosRejected    14.176 ± 3.861  ns/op
original                32.950 ± 1.062  ns/op
```

So this is roughly 45% faster than what we had.

This includes a big chunk of #124676 - but not the behavior change -
just the code that allowed it.
@nik9000
Copy link
Member Author

nik9000 commented Apr 8, 2025

Backports in.

nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in elastic#126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
nik9000 added a commit that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in #126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in elastic#126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in elastic#126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
elasticsearchmachine pushed a commit that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in #126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
elasticsearchmachine pushed a commit that referenced this pull request Apr 29, 2025
I wrote an `&&` when I meant and `||` in #126338 and that caused some
impressive looking line noise to parse as valid ipv4 addresses.
Randomized tests caught it eventually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants