Skip to content
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

Optimize ContentPath#pathAsText #98244

Merged
merged 10 commits into from
Sep 13, 2023

Conversation

dorukguner
Copy link
Contributor

This pr optimizes calls to ContentPath#pathAsText through the following changes:

  • When at the root we return the provided string directly
  • When called on a sibling or child field the previously built path is maintained to prevent appending the same top-level fields again

The case in which fields that have been previously added to the path are removed is handled in ContentPath#remove by clearing the existing StringBuilder.

Tests for ContentPath#pathAsText have been added in a separate commit to the optimization to allow for easy validation that the tests are correct.

Addresses #94544

@cla-checker-service
Copy link

cla-checker-service bot commented Aug 6, 2023

💚 CLA has been signed

@elasticsearchmachine elasticsearchmachine added v8.10.0 needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels Aug 6, 2023
@slobodanadamovic slobodanadamovic added :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team labels Aug 14, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Aug 14, 2023
@quux00 quux00 added v8.11.0 and removed v8.10.0 labels Aug 16, 2023
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dorukguner, sorry for the delay in getting to this and thanks for picking it up.
I like the solution and the tests are great. Since we have tests now I would like to go a step further and optimize your solution even a bit more. I left a few suggestions for that, let me know what you think.

@cbuescher cbuescher self-assigned this Sep 8, 2023
@cbuescher cbuescher mentioned this pull request Sep 8, 2023
@dorukguner
Copy link
Contributor Author

Hi @cbuescher, thanks for the feedback.

I've merged the extra test cases I had into the new main test class and I've also optimised ContentPath a little further.

I realised we didn't need both an array of strings for the path and a string builder. We can have just a string builder while keeping track of the indexes in which the delimiters were added, and using the add and remove methods to modify the string builder directly. This has removed the need for any loops and any extra indexes.

Please let me know what you think about the new optimisations, I'm open to any other suggestions you may have.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dorukguner thanks a lot, I think the idea of just keeping one datastructure for the whole path and keeping around the pointers to the parts is great and the tests are also covering this nicely. I left two small comments but will prepare this PR for testing and merging while you address those.

@cbuescher
Copy link
Member

Just running a check before the final changes to see if this breaks anything else.

@elasticsmachine test this please

@cbuescher
Copy link
Member

@dorukguner could you also run ./gradlew :server:spotlessApply to apply our formatting rules to the modified classes?

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, LGTM. Will need to run full test suite before merging.

@cbuescher
Copy link
Member

@elasticmachine test this please

@cbuescher
Copy link
Member

@elasticmachine test this please

@cbuescher
Copy link
Member

@elasticmachine update branch

@cbuescher
Copy link
Member

@elasticmachine test this please

@cbuescher cbuescher merged commit db22afa into elastic:main Sep 13, 2023
@dorukguner dorukguner deleted the dorukguner/optimize-content-path branch September 13, 2023 11:02
@cbuescher
Copy link
Member

@dorukguner huzzah, all passed. Thanks for the change and the iterations, merged to main branch now. I think this is a great change that makes using this class a lot less wasteful.

cbuescher added a commit to cbuescher/elasticsearch that referenced this pull request Oct 30, 2023
cbuescher added a commit that referenced this pull request Oct 30, 2023
Some benchmarks indicate that parts of the change made in #98244 is negatively
affecting document parsing. This change reverts it until we have better benchmarks
that support it or a solution that avoids the Stack datastructure most likely contributing
to this. This reverts commit db22afa.
cbuescher added a commit to cbuescher/elasticsearch that referenced this pull request Oct 30, 2023
)

Some benchmarks indicate that parts of the change made in elastic#98244 is negatively
affecting document parsing. This change reverts it until we have better benchmarks
that support it or a solution that avoids the Stack datastructure most likely contributing
to this. This reverts commit db22afa.
elasticsearchmachine pushed a commit that referenced this pull request Oct 30, 2023
Some benchmarks indicate that parts of the change made in #98244 is negatively
affecting document parsing. This change reverts it until we have better benchmarks
that support it or a solution that avoids the Stack datastructure most likely contributing
to this. This reverts commit db22afa.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants