Skip to content

Improve nested set build performance#2273

Merged
anvit merged 4 commits intoartefactual:qa/2.xfrom
danloveg:dev/issue-2272-improve-nested-set-build-time
Feb 18, 2026
Merged

Improve nested set build performance#2273
anvit merged 4 commits intoartefactual:qa/2.xfrom
danloveg:dev/issue-2272-improve-nested-set-build-time

Conversation

@danloveg
Copy link
Copy Markdown
Contributor

Closes #2272

Reduce the execution time of propel:build-nested-set by around 90% by applying a couple of performance optimizations:

  • Batch-update lft and rgt values instead of writing them one-by-one
  • Use [] to create child-parent array instead of array_push()

This improves performance by reducing the number of SQL statements that
need to be executed.
[] is a direct language construct of PHP and does not add the overhead
of calling a function like array_push.
Since the ids come from the database, and the lft and rgt values are
constructed in this class, there is no need for using placeholders for
SQL injection.

Using the IDs directly in this manner makes the code easier to read
*and* it's much faster.
@sarah-mason sarah-mason added the Community Pull requests that have been contributed from community members outside Artefactual label Jan 19, 2026
$ids[] = $node['id'];
}

$sql = sprintf(
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.

Neat! Batching these up as a single big query should be a big improvement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For sure, it was a huge performance improvement from my testing!

Copy link
Copy Markdown
Contributor

@anvit anvit left a comment

Choose a reason for hiding this comment

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

Thanks @danloveg !

@anvit anvit added this to the 2.11 milestone Feb 18, 2026
@anvit anvit merged commit db575a3 into artefactual:qa/2.x Feb 18, 2026
6 checks passed
@danloveg danloveg deleted the dev/issue-2272-improve-nested-set-build-time branch February 18, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Pull requests that have been contributed from community members outside Artefactual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance issue: Nested set takes a long time to build for many information objects

3 participants