Skip to content

Micro-optimisations: Delivery API node parse improvement - #23506

Merged
AndyButland merged 5 commits into
umbraco:mainfrom
patrickdemooij9:NodeParseImprovement
Jul 31, 2026
Merged

AndyButland merged 5 commits into
umbraco:mainfrom
patrickdemooij9:NodeParseImprovement

Conversation

@patrickdemooij9

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below (I think this is already covered by OutputExpansionStrategyV2Tests)

Description

The Node.Parse currently goes through each char in a string and checks if there are certain characters. Because we already know the subset of characters that we want to match on, we can just jump to the characters that we need and then resolve everything before that to reduce allocations.

I ran two benchmarks. The impact is not that big, but it gets bigger with the amount of text included.

Value = $all

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
Base 80.49 ns 27.05 ns 1.483 ns 1.00 0.02 0.0312 392 B 1.00
TestOneValue 51.29 ns 27.59 ns 1.512 ns 0.64 0.02 0.0242 304 B 0.78

Value = properties[header,footerGrid,footerLegal,pageTitles]

Method Mean Error StdDev Ratio Gen0 Allocated Alloc Ratio
Base 458.0 ns 89.94 ns 4.93 ns 1.00 0.1788 2264 B 1.00
TestOneValue 138.7 ns 7.17 ns 0.39 ns 0.30 0.0639 816 B 0.36

@github-actions

Copy link
Copy Markdown

Hi there @patrickdemooij9, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Comment thread src/Umbraco.Cms.Api.Common/Rendering/ElementOnlyOutputExpansionStrategy.cs Outdated
Comment thread src/Umbraco.Cms.Api.Common/Rendering/ElementOnlyOutputExpansionStrategy.cs Outdated
@AndyButland AndyButland changed the title Delivery API Node parse improvement Micro-optimisations: Delivery API node parse improvement Jul 31, 2026

@AndyButland AndyButland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks again @patrickdemooij9, also looks good. I've pushed a few more targeted tests, which did lead to me seeing a minor regression in functionality. It's only one for a malformed request, but to be 100% sure I've ensured the behaviour hasn't changed.

I've also run some automated smoke tests with the delivery API to ensure the expansion behaviour works as before.

@patrickdemooij9

Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to look at them @AndyButland . Do you write the tests yourself or do you generate them? If so, is there a standard prompt I might be able to use? Would save you time on my pull requests next time

@AndyButland

Copy link
Copy Markdown
Contributor

I'm generating and then reviewing them. Nothing very sophisticated - just working with Claude and asking it to verify coverage of the functionality that's changed, and where it's found lacking, generate unit tests and verify the pass both before and after the refactoring.

@AndyButland
AndyButland merged commit 486d442 into umbraco:main Jul 31, 2026
29 checks passed
AndyButland added a commit that referenced this pull request Jul 31, 2026
* Delivery API Node parse improvement

* PR feedback from myself

* Further minor optimisation in ElementOnlyOutputExpansionStrategy.

* Add tests and revert a minor change to previous behaviour.

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
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