Repository navigation
perf: stop loading scikit-learn at agent start-up - #551
Open
ahmad-ajmal wants to merge 1 commit into
Open
ahmad-ajmal wants to merge 1 commit into
ahmad-ajmal wants to merge 1 commit into
Conversation
event_stream imported sklearn's TfidfVectorizer only to pick 5 keywords from one message. That import loaded scikit-learn, scipy and pandas: 154 of the 190 native libraries the agent loads at start-up, each re-checked by macOS after every reboot. Replace it with plain Python that gives the same keywords (checked on 3,014 texts), drop scikit-learn from requirements and the launch check, and regenerate the locks (removes scikit-learn, scipy, joblib, threadpoolctl, cloudpickle).
ahmad-ajmal
marked this pull request as ready for review
December 3, 2026 14:54
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
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.
Why
After a reboot, macOS checks every native library again the first time it loads. One launch after a reboot took 42 s, and 22 s of that was imports stalled behind about 230 of those checks.
154 of the 190 native libraries the agent loads at start-up come from one line in
agent_core/core/impl/event_stream/event_stream.py:That import pulls in scikit-learn, scipy and pandas. It is used only by
_extract_keywords, which picks 5 keywords from a single message to label a long output that gets saved to a file.What changes
_extract_keywordsis now plain Python: the same tokenizer, scikit-learn's English stop words, single words and word pairs, ranked by count. With one document and default settings, TF-IDF ranks terms by count, so the keywords are the same. I compared old and new on 3,014 texts, from whole repository files and random slices of them to Unicode and empty input. All 3,014 matched.event_stream/_stop_words.pyis scikit-learn's 318-word list, copied with its BSD-3 licence notice.requirements.txtand from the launch dependency check inapp/runtime_preflight.py. If it stayed in the check, launches would fail with a missing-dependency error.tests/test_event_stream_keywords.pycovers:Results (macOS, Apple silicon)
The launch after a reboot is where most of the gain should be, but I haven't measured it with this change yet.
Testing
V1.4.6.