Skip to content

perf: recording performance optimizations — round 2#84

Merged
fank merged 15 commits intomainfrom
worktree-keen-elm-lips
Feb 28, 2026
Merged

perf: recording performance optimizations — round 2#84
fank merged 15 commits intomainfrom
worktree-keen-elm-lips

Conversation

@fank
Copy link
Member

@fank fank commented Feb 28, 2026

Summary

Follows PR #83. Further reduces CPU and extension overhead in the capture loop and supporting functions.

  • Cache ACE function existence checks: Three isNil "ace_..." string checks that ran per unit per frame are now cached once at init, since ACE presence can't change at runtime. Also caches objectParent to avoid duplicate calls.
  • Vehicle state deduplication: Same pattern as the unit dedup from PR perf: recording performance optimizations #83 — uses a frame placeholder at index 5 so comparisons ignore frame number, skips :VEHICLE:STATE: extension calls for unchanged vehicles (parked/static).
  • Skip turret lookup for unarmed vehicles: Caches hasTurret per vehicle at init using weaponsTurret. Skips CBA_fnc_turretDir for unarmed vehicles, eliminating CBA warning log spam for civilian cars etc.
  • Replace count-for-side-effects with forEach: Three locations used { ... false } count purely for side effects — replaced with idiomatic forEach.
  • Cache getClass results: Hashmap cache keyed by vehicle typeOf eliminates redundant config lookups for vehicles of the same type.
  • Replace BIS_fnc_inString with native in: Drops scripted function overhead in handleMarkers and getUnitType — HEMTT linter confirmed in is faster than find.
  • Accumulate global telemetry counts: Sums per-side accumulators instead of re-iterating all arrays for global counts, eliminating 4 redundant full-array passes.

Test plan

  • hemtt build passes (verified locally, zero warnings)
  • Run a mission with mixed armed/unarmed vehicles — verify turret data still recorded for armed vehicles
  • Run a mission with parked vehicles — verify reduced extension call volume
  • Check RPT logs — CBA turret warnings should no longer appear for unarmed vehicles
  • Verify ACE medical data still recorded correctly when ACE is loaded
  • Verify marker filtering still works correctly
  • Verify telemetry global counts match expected values

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on a second round of performance optimizations for the recording system. The changes aim to reduce CPU and extension overhead by caching frequently accessed data, deduplicating state transmissions for units and vehicles, and streamlining data collection loops. The overall impact is a more efficient and less resource-intensive recording process.

Highlights

  • ACE Function Existence Checks Cached: The pull request caches the existence checks for several ACE functions (e.g., ace_common_fnc_isAwake, ace_medical_status_fnc_hasStableVitals) once at initialization. This eliminates redundant isNil checks that previously ran per unit per frame, significantly reducing CPU overhead.
  • Vehicle and Unit State Deduplication: Introduced logic to deduplicate :SOLDIER:STATE: and :VEHICLE:STATE: extension calls. Unit and vehicle data are now compared against their last recorded states, and transmissions are skipped if no significant changes have occurred. A frame placeholder is used to ensure comparisons ignore the frame number itself.
  • Turret Lookup Optimization for Unarmed Vehicles: The hasTurret status is now cached per vehicle during initialization. This allows the system to skip CBA_fnc_turretDir calls for unarmed vehicles, preventing unnecessary processing and eliminating CBA warning log spam for civilian vehicles.
  • Exclusion List Caching: Configuration settings for excluding certain kinds, classes, and markers from recording are now parsed once at initialization and stored in global variables. This avoids repeated parsing of these settings within loops, improving performance.
  • Telemetry Loop Optimization: The telemetry data collection loop has been optimized by replacing multiple select and count operations with more efficient direct iteration and counter increments. This reduces the overhead associated with gathering statistics for units, dead men, groups, and vehicles.
Changelog
  • addons/recorder/fnc_captureLoop.sqf
    • Implemented weapon state tracking for units to reduce getUnitType calls.
    • Introduced player score state tracking for units to avoid redundant data transmission.
    • Replaced direct isNil checks for ACE functions with cached global variables.
    • Modified unit data recording to use a frame placeholder and deduplicate identical state transmissions.
    • Cached objectParent to prevent repeated function calls.
    • Added caching for hasTurret status per vehicle to optimize turret data collection.
    • Updated vehicle data recording to use a frame placeholder and deduplicate identical state transmissions.
  • addons/recorder/fnc_handleMarkers.sqf
    • Initialized and utilized a cached global variable for marker exclusion lists to improve performance.
    • Replaced repeated parseSimpleArray calls with the cached exclusion list.
  • addons/recorder/fnc_init.sqf
    • Initialized global variables for caching ACE function existence checks.
    • Initialized global variables for caching vehicle kind, class, and marker exclusion lists.
  • addons/recorder/fnc_isKindOfApc.sqf
    • Refactored the isKindOf check for APCs to use findIf for improved readability and potential performance.
  • addons/recorder/fnc_telemetryLoop.sqf
    • Optimized telemetry data collection by replacing multiple select and count operations with single forEach loops and direct counter increments for units, dead men, groups, and vehicles.
Activity
  • This pull request continues the performance optimization efforts initiated in PR perf: recording performance optimizations #83.
  • The author has outlined several remaining planned tasks for future improvements, indicating ongoing development.
  • A detailed test plan has been provided to ensure the changes function as expected and verify performance gains.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several significant performance optimizations to the recording loop, primarily by caching frequently accessed data and reducing redundant computations. The changes include caching ACE function existence checks, vehicle and unit state deduplication to minimize extension calls, and optimizing lookups for vehicle turrets and entity exclusion lists. The refactoring in fnc_telemetryLoop.sqf to use forEach instead of multiple select calls is a particularly impactful improvement. My review found one minor opportunity to improve code readability in the new turret direction logic, but overall the changes are well-implemented and align with the stated goals of the pull request.

@fank fank marked this pull request as ready for review February 28, 2026 17:06
@fank
Copy link
Member Author

fank commented Feb 28, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several excellent performance optimizations to the capture loop and supporting functions. Caching ACE function checks, vehicle state deduplication, and using native operators are all great improvements.

However, I've found a correctness issue in the optimization for telemetry global counts. The new logic undercounts entities by only considering the four main sides, which will lead to inaccurate telemetry. I've left a detailed comment with a suggestion to revert that specific part of the change to ensure data correctness.

Overall, great work on improving performance. Once the telemetry issue is addressed, this will be a solid contribution.

@fank fank merged commit 424bed3 into main Feb 28, 2026
1 check passed
@fank fank deleted the worktree-keen-elm-lips branch February 28, 2026 18:30
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