Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up method StreamAvailabilityStrategy.check_availability by 9% in PR #45673 (async-job-salesforce/cdk-release) #45679

Open
wants to merge 1 commit into
base: async-job-salesforce/cdk-release
Choose a base branch
from

Conversation

codeflash-ai[bot]
Copy link

@codeflash-ai codeflash-ai bot commented Sep 19, 2024

⚡️ This pull request contains optimizations for PR #45673

If you approve this dependent PR, these changes will be merged into the original PR branch async-job-salesforce/cdk-release.

This PR will be automatically closed if the original PR is merged.


📄 StreamAvailabilityStrategy.check_availability() in airbyte-cdk/python/airbyte_cdk/sources/streams/concurrent/adapters.py

📈 Performance improved by 9% (0.09x faster)

⏱️ Runtime went down from 29.5 microseconds to 27.0 microseconds

Explanation and details

Certainly! Here is an optimized version of the given code. The primary optimization focuses on reducing redundant checks and making use of exception handling in a more efficient manner.

Optimizations made.

  1. Reduced Redundant Calls:

    • hasattr and callable combined into a single conditional check.
    • Checked for method existence and direct callability within the try block.
  2. Exception Handling.

    • Moved the ExceptionWithDisplayMessage raising to a more concise single line using the ternary operator.

Explanation.

  1. Conditional Check: Combining hasattr and callable ensures that check_availability method existence and callability are checked in a streamlined manner.
  2. Exception Handling Clarity: Using a ternary operator for raising ExceptionWithDisplayMessage or re-raising the caught exception makes the code more readable and slightly faster due to less branching.

Correctness verification

The new optimized code was tested for correctness. The results are listed below.

✅ 1 Passed − ⚙️ Existing Unit Tests

(click to show existing tests)
- sources/streams/concurrent/test_adapters.py

✅ 0 Passed − 🌀 Generated Regression Tests

(click to show generated tests)
# imports
import logging
from abc import ABC, abstractmethod
from typing import Any, Optional

import pytest  # used for our unit tests
from airbyte_cdk.sources import Source
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.concurrent.adapters import \
    StreamAvailabilityStrategy
from airbyte_cdk.sources.streams.concurrent.availability_strategy import \
    AbstractAvailabilityStrategy

# unit tests

# Test Stream with `check_availability` Method Returning Available









🔘 (none found) − ⏪ Replay Tests

… 9% in PR #45673 (`async-job-salesforce/cdk-release`)

Certainly! Here is an optimized version of the given code. The primary optimization focuses on reducing redundant checks and making use of exception handling in a more efficient manner.



### Optimizations made.
1. **Reduced Redundant Calls**: 
   - `hasattr` and `callable` combined into a single conditional check.
   - Checked for method existence and direct callability within the try block.
   
2. **Exception Handling**.
   - Moved the `ExceptionWithDisplayMessage` raising to a more concise single line using the ternary operator.

### Explanation.
1. **Conditional Check**: Combining `hasattr` and `callable` ensures that `check_availability` method existence and callability are checked in a streamlined manner.
2. **Exception Handling Clarity**: Using a ternary operator for raising `ExceptionWithDisplayMessage` or re-raising the caught exception makes the code more readable and slightly faster due to less branching.
@codeflash-ai codeflash-ai bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Sep 19, 2024
Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Sep 19, 2024 4:40pm

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@octavia-squidington-iii octavia-squidington-iii added CDK Connector Development Kit community labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit ⚡️ codeflash Optimization PR opened by Codeflash AI community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants