You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up method LangFuseTracer.get_required_variable_names by 18% in PR #7183 (feat/global_vars_tracing)
To improve the performance of the Python program, we need to consider areas that could potentially cause slowdowns. One primary area is unnecessary initializations and redundant calculations. Here's an optimized version.
### Changes and Improvements.
1. **Usage of `__slots__`:**
- Added `__slots__` to the class to avoid the creation of `__dict__` for storing instance attributes. This can save memory and speed up attribute access.
2. **Optimized string splitting:**
- Changed `trace_name.split(" - ")[-1]` to `trace_name.rsplit(" - ", 1)[-1]`. This is more efficient for the intended use case because `rsplit` with max split parameter = 1 performs a single split operation from the right.
3. **Inline the setup check:**
- Combined the check of `config` existence and setup in one line using `bool()` for clarity.
By implementing these changes, the code should perform more efficiently in terms of both speed and memory usage. The function signatures and behavior remain same as before.
0 commit comments