Skip to content

⚡ Bolt: Optimize Rack Count Lookup Performance#173

Open
mleem97 wants to merge 1 commit into
mainfrom
bolt-optimize-rack-count-2044604395868426080
Open

⚡ Bolt: Optimize Rack Count Lookup Performance#173
mleem97 wants to merge 1 commit into
mainfrom
bolt-optimize-rack-count-2044604395868426080

Conversation

@mleem97

@mleem97 mleem97 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced the O(N) FindObjectsOfType<Rack>() call in GregFacilityModule with an O(1) array index lookup via NetworkMap.instance.GetNumberOfDevices().
🎯 Why: FindObjectsOfType scans the entire object hierarchy, which is very expensive in IL2CPP environments and causes CPU hitches, especially in late-game scenarios.
📊 Impact: Reduces the time complexity from O(N) to O(1) for getting rack counts, significantly improving performance on each API call.
🔬 Measurement: Verified the optimization compiles successfully and preserves functionality by utilizing a safe fallback to FindObjectsOfType when the NetworkMap singleton is null. Tests pass cleanly.


PR created automatically by Jules for task 2044604395868426080 started by @mleem97

@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

The PR introduces a performance optimization for rack count lookups, transitioning from O(N) to O(1) via the NetworkMap singleton. While Codacy indicates the code is up to standards, a critical architectural conflict exists: the implementation includes a fallback to FindObjectsOfType, which contradicts the performance guidelines established in .jules/bolt.md. This fallback can cause frame hitches in IL2CPP environments and should be removed in favor of a neutral return value (0).

Furthermore, although the PR logic adds complexity (+3) and multiple defensive branches (null checks, length validation), no new tests were included to verify these paths. The PR should not be merged until the performance conflict is resolved and the missing test scenarios are addressed.

About this PR

  • The logic in GregFacilityModule.cs has increased in complexity due to new defensive checks, yet no test files were modified or added. Automated verification is required for the new null and bounds-checking logic.
  • The implementation contains a conflict between the acceptance criteria and the project's performance guidelines. Retaining FindObjectsOfType as a fallback preserves the O(N) performance bottleneck that this PR aims to solve. Given the IL2CPP context mentioned in the guidelines, the fallback should be removed.

Test suggestions

  • Verify GetRackCount returns the value at index 2 when NetworkMap is initialized and has sufficient data.
  • Verify GetRackCount falls back to FindObjectsOfType when NetworkMap.instance is null.
  • Verify GetRackCount falls back to FindObjectsOfType when GetNumberOfDevices() returns null or a short array.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify GetRackCount returns the value at index 2 when NetworkMap is initialized and has sufficient data.
2. Verify GetRackCount falls back to FindObjectsOfType when NetworkMap.instance is null.
3. Verify GetRackCount falls back to FindObjectsOfType when GetNumberOfDevices() returns null or a short array.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

}

// Graceful fallback for uninitialized game states
return UnityEngine.Object.FindObjectsOfType<global::Il2Cpp.Rack>().Length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Suggestion: The fallback to FindObjectsOfType contradicts the performance guidelines in .jules/bolt.md (lines 24-26), which identify it as an expensive O(N) operation. If the NetworkMap is not initialized, it is more performant to return 0 instead of scanning the entire object hierarchy.

Suggested change
return UnityEngine.Object.FindObjectsOfType<global::Il2Cpp.Rack>().Length;
return 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant