ynput / ayon-usd

USD Addon for AYON.
Apache License 2.0
4 stars 1 forks source link

Research Request: Refactor Recursive File Pinning to Use Multithreading #30

Open Lypsolon opened 2 months ago

Lypsolon commented 2 months ago

Is there an existing issue for this?

Please describe the feature you have in mind and explain what the current shortcomings are?

Issue Description:

The current implementation of the file pinning process in our codebase uses a recursive approach. While this method works effectively for smaller structures, it can potentially hit Python's recursion limit when dealing with larger structures. This not only risks stack overflow errors but also may not be the most performant solution for handling large-scale operations.

To address these concerns, I propose researching alternative methods that can:

Action Points for Research:

Additional Information:

This research will guide us in refactoring the file pinning process to be more robust and performant, ensuring scalability as the codebase grows.

How would you imagine the implementation of the feature?

Implementation Suggestion: Multithreading with a Tree/Graph Structure

To implement the solution, we could use a tree or graph structure to represent the data. Here's how the approach would work:

  1. Tree/Graph Structure:

    • Each Sdf.Layer would represent an individual node in the tree/graph structure.
    • Nodes would be connected to their parent nodes, forming a hierarchy that mirrors the structure of the files.
    • Every Parent node needs to have an pointer to the child nodes for better traversal
  2. Multithreading:

    • Once the structure is established, each node (representing a traversal element or layer) could be processed on a separate thread.
    • This approach would allow for concurrent processing of multiple nodes, improving performance and scalability.
  3. Main Thread Coordination:

    • It would distribute tasks to worker threads, monitor their progress, and handle any exceptions or errors that arise during processing.
    • This approach ensures that the main thread remains available to oversee the operation and handle any issues that may occur without being bogged down by the actual file processing.

This method would allow us to avoid recursion limits by eliminating deep recursion and leveraging multithreading to parallelize the workload, resulting in improved performance, particularly with large data structures.

Are there any labels you wish to add?

Describe alternatives you've considered:

No response

Additional context:

No response