Skip to content

Conversation

@EdmondDantes
Copy link
Contributor

   Comprehensive performance optimization of TrueAsync API to eliminate expensive EG(exception) checks in hot execution paths by refactoring function signatures from void to
   bool and replacing exception-based error handling with direct return value checks.

   Key changes:
   - Updated function typedefs: zend_async_event_del_callback_t, zend_async_event_stop_t, zend_async_event_dispose_t (void→bool)
   - Refactored zend_async_callbacks_remove to return bool
   - Updated all del_callback, stop, and dispose function implementations with proper return values
   - Fixed forward declarations compatibility issues
   - Optimized all function call sites to use if (!function()) return false; pattern instead of EG(exception) checks
   - Applied optimization to ~80 functions across coroutine, scope, curl, and libuv reactor modules

   Performance impact:
   Replaces expensive exception checks with fast boolean operations in critical async execution paths.

       Comprehensive performance optimization of TrueAsync API to eliminate expensive EG(exception) checks in hot execution paths by refactoring function signatures from void to
       bool and replacing exception-based error handling with direct return value checks.

       Key changes:
       - Updated function typedefs: zend_async_event_del_callback_t, zend_async_event_stop_t, zend_async_event_dispose_t (void→bool)
       - Refactored zend_async_callbacks_remove to return bool
       - Updated all del_callback, stop, and dispose function implementations with proper return values
       - Fixed forward declarations compatibility issues
       - Optimized all function call sites to use if (!function()) return false; pattern instead of EG(exception) checks
       - Applied optimization to ~80 functions across coroutine, scope, curl, and libuv reactor modules

       Performance impact:
       Replaces expensive exception checks with fast boolean operations in critical async execution paths.
@EdmondDantes EdmondDantes added this to the Stabilization2 milestone Sep 25, 2025
@EdmondDantes EdmondDantes self-assigned this Sep 25, 2025
@EdmondDantes EdmondDantes added the enhancement New feature or request label Sep 25, 2025
@EdmondDantes EdmondDantes linked an issue Sep 25, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a comprehensive performance optimization of the TrueAsync API by refactoring function signatures from void to bool and replacing expensive EG(exception) checks with direct return value checks across ~80 functions.

  • Converts event system function typedefs and implementations from void to bool return types
  • Refactors scheduler and coroutine functions to return success/failure status directly
  • Updates all call sites to use fast boolean checks instead of exception state inspection

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
scope.c Updates scope event handlers and disposal functions to return bool, optimizes timer event callback handling
scheduler.h Changes scheduler function signatures from void to bool
scheduler.c Implements bool return values for scheduler launch, suspend, and enqueue functions
libuv_reactor.c Converts all libuv event handlers (poll, timer, signal, etc.) to return bool with proper error handling
coroutine.h Updates coroutine function signatures to return bool
coroutine.c Implements bool returns for suspend, resume, cancel, and event system functions
async_API.c Updates spawn and microtask functions with boolean return patterns
async.c Optimizes main async functions to use boolean checks
CHANGELOG.md Documents the performance optimization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +355 to +357
if (!event->del_callback(event, callback)) {
// Optimized: ignore del_callback failure in callback context
}
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

[nitpick] Silently ignoring the failure contradicts the purpose of returning boolean status. Consider logging the failure or handling it appropriately, even if it's just a debug trace.

Copilot uses AI. Check for mistakes.
@EdmondDantes EdmondDantes merged commit 4e76bdf into main Sep 25, 2025
1 check passed
@EdmondDantes EdmondDantes deleted the 59-optimize-the-execution-path-for-true-async-api-error-cases branch September 25, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize the execution path for TRUE ASYNC API error cases

2 participants