Skip to content

Optimize hierarchy model: use get_rest_folders instead of get_folders_hierarchy - #2073

Merged
iLLiCiTiT merged 3 commits into
developfrom
enhancement/optimize_hierarchy_model_folders_query
Sep 18, 2026
Merged

iLLiCiTiT merged 3 commits into
developfrom
enhancement/optimize_hierarchy_model_folders_query

Conversation

@BigRoy

@BigRoy BigRoy commented Sep 17, 2026

Copy link
Copy Markdown
Member

Changelog Description

Query folders with get_rest_folders instead of get_folders_hierarchy for general speed improvement.

Additional info

Performance for 10,328 folders, local server, 10 repeats

  • OLD (get_folders_hierarchy full call) mean: 796.5 ms | median: 629.5 ms
  • NEW (get_rest_folders full call) mean: 235.8 ms | median: 181.6 ms
  • NEW + __slots__ (full call) mean: 222.5 ms | median: 186.6 ms

The slots call is a neglible ~4-6% faster in processing, however it reduces its memory usage by +/-46% and since we do keep these in cache it's a nice bonus (even though we're talking only 403 KiB saved for this dataset). Since it's a minor tweak I added it.

Testing notes:

  1. Launcher/workfiles etc. folders list still work as intended.

…hy` for general speed improvement.

Performance for 10,328 folders, local server, 10 repeats
- OLD (`get_folders_hierarchy` full call) mean: 796.5 ms | median: 629.5 ms
- NEW (`get_rest_folders` full call) mean: 235.8 ms | median: 181.6 ms
- NEW + `__slots__` (full call) mean: 222.5 ms | median: 186.6 ms

The slots call is a neglible ~4-6% faster in processing, however it reduces its memory usage by +/-46% and since we do keep these in cache it's a nice bonus (even though we're talking only 403 KiB saved for this dataset)
@BigRoy
BigRoy requested review from iLLiCiTiT and a lite review from Copilot September 17, 2026 20:11
@BigRoy BigRoy self-assigned this Sep 17, 2026
@BigRoy BigRoy added the type: enhancement Improvement of existing functionality or minor addition label Sep 17, 2026
@ynbot ynbot added the size/XS label Sep 17, 2026

Copilot AI 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.

🟡 Changes recommended

The new REST parsing path currently normalizes path differently than other constructors, which can create inconsistent cached paths (e.g. potential //...) and break path-based lookups/filters.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR optimizes the hierarchy folder model by switching the folder-cache refresh query from ayon_api.get_folders_hierarchy (tree) to ayon_api.get_rest_folders (flat list), with an additional memory optimization on the cached FolderItem instances.

Changes:

  • Replace hierarchy-tree traversal with a flat REST folders query in the folder cache refresh path.
  • Introduce FolderItem.__slots__ to reduce per-item memory overhead in cached folder items.
  • Add FolderItem.from_rest_data(...) for constructing cached items from REST payloads.
File summaries
File Description
client/ayon_core/tools/common_models/hierarchy.py Switches folder querying to get_rest_folders, adds a REST-to-model constructor, and applies __slots__ to reduce memory usage.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client/ayon_core/tools/common_models/hierarchy.py
Comment thread client/ayon_core/tools/common_models/hierarchy.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ynbot ynbot moved this to Review In Progress in PR reviewing Sep 17, 2026
@github-project-automation github-project-automation Bot moved this from Review In Progress to Merge Requested in PR reviewing Sep 18, 2026
@iLLiCiTiT
iLLiCiTiT merged commit 29e9aa5 into develop Sep 18, 2026
7 checks passed
@iLLiCiTiT
iLLiCiTiT deleted the enhancement/optimize_hierarchy_model_folders_query branch September 18, 2026 07:37
@github-project-automation github-project-automation Bot moved this from Merge Requested to Done in PR reviewing Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS type: enhancement Improvement of existing functionality or minor addition

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants