-
Notifications
You must be signed in to change notification settings - Fork 22
Runtime annotation fixes #501
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
codeflash-ai bot
added a commit
that referenced
this pull request
Jul 3, 2025
… (`runtime-fixes-2`) **Key optimizations:** - Avoid multiple `isinstance` calls by caching `type(node)` in a variable and using identity checks against the expected types (`_ast_Name`, `_ast_Attribute`). - This speeds up the type checks, since identity comparison is faster than repeated isinstance checks, and in this hot path, there are only two accepted types.
⚡️ Codeflash found optimizations for this PR📄 18% (0.18x) speedup for
|
codeflash-ai bot
added a commit
that referenced
this pull request
Jul 3, 2025
…ntime-fixes-2`)
Here is an optimized version of your program, focused on **runtime efficiency** while preserving behavior and all required side effects.
#### Key Optimizations.
1. **Avoid Repeated get_user_id() Calls**:
- The main bottleneck is that `get_user_id()` (which may call an HTTP endpoint) is called on every telemetry event including when initializing.
- Cache the user_id globally after first retrieval (thread-safe for CPython).
- This avoids a heavy call per event.
2. **Share UserID for Session**:
- When Posthog is initialized, fetch and store the user id; all further `ph()` calls use the cached id (only refresh/cache once per process run).
3. **Micro-optimizations**.
- In-place property dict building (no need to recreate or update on every call).
- Remove redundant conditional short circuit (`properties or {}` is fast, so just keep).
- Keep initialization/finalization path short.
4. **No Change to Function Signatures or Comments**:
- Extra helpers prefixed with `_` as per request.
---
---
**Summary of Wins:**
- Only a single (potentially slow) `get_user_id()` call per process lifetime (amortizes network cost).
- No unnecessary copying or property dict overhead.
- No behavioral changes; all comments/statements preserved for modified code blocks.
Let me know if you’d like further memory or threading optimizations!
⚡️ Codeflash found optimizations for this PR📄 116,400% (1,164.00x) speedup for
|
misrasaurabh1
approved these changes
Jul 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.