Repository navigation
Conversation
Interpreter completions check runtime attributes with getattr_static, which walks the mro many times per lookup. Skip the raised TypeError in _is_type and the KeyError in the class dict lookups, compute the metaclass _shadowed_dict check once per metaclass, read __mro__ directly for classes whose metaclass is exactly type, and reuse _check_class for the metaclass lookup. Custom metaclasses and shadowed __dict__ keep the old path, so results do not change. test_list completions benchmark: 322.4 ms -> 279.6 ms (about 12.5% faster, median of 3 runs). Co-Authored-By: Aiden <aiden@weco.ai>
Owner
|
Wow you LLM bros are really really useless. Stop wasting tokens and energy. Your just heating the planet. |
2 tasks done
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.
TL;DR
getattr_staticand its helpers injedi/inference/compiled/getattr_static.pyfaster.__dict__check once per metaclass.test_listcompletions benchmark, median of 3 runs: 322.4 ms -> 279.6 ms, about 12.5% faster.master.What & Why
jedi.Interpreterchecks attributes of runtime objects withgetattr_static. Each check walks the mro many times. Before this change, the code did extra work on every walk:_is_typeraised and caught aTypeErrorfor every non-type object._check_classand_shadowed_dictraised and caught aKeyErrorfor each mro entry without the attribute._check_classcomputed_shadowed_dict(type(entry))again for every mro entry, also when the metaclass did not change.Now the code does these checks without exceptions.
_is_typeusesissubclass(type(obj), type). This is the same check thattype.__mro__.__get__does before it raises. The dict lookups use.get(attr, _sentinel)on the real classmappingproxy. Other mappings keep the oldtry/except KeyErrorpath._check_classcomputes_shadowed_dictonce for each new metaclass._static_getmroreadsklass.__mro__directly when the metaclass is exactlytype. The metaclass loop ingetattr_staticnow calls_check_class, because that loop did the same work.The output stays identical. Each new check returns the same value as the old exception path. Custom metaclasses and shadowed
__dict__still use the old code.Results
Median time per call, same machine,
masteragainst this branch:test_listsources (list ofstr/int, 5 completions)Interpreter:os.paon theosmoduleInterpreter:__slots__instance,s.Interpreter:Enumclass (custom metaclass),Color.RED.naScriptonly, no runtime objects (json.dum)The
EnumandScriptrows show that there is no slowdown where the fast path does not apply.Why this is safe and easy to maintain
The change is small: about 30 lines in one file, inside the existing private helpers. Each new check gives the same result as the old exception path, so behaviour and output do not change. Classes with custom metaclasses or a shadowed
__dict__still go through the old code.test/test_api/test_interpreter.pycovers properties,__getattr__and side-effect objects. A separate check gave the same completions asmasterfor metaclasses,__slots__and a shadowed__dict__.Validation
pytest test/test_api/test_interpreter.py test/test_inference/test_signature.py test/test_api/test_classes.py test/test_inference/test_imports.py test/test_inference/test_compiled.py-> 512 passed, 5 skipped, 4 xfailed (same as
master).pytest test: 3883 passed. The same 44 tests fail onmasterand on this branch in my environment (pytest-plugin and namespace-package tests). This change adds no new failures.test_listsources fromtest/test_api/test_interpreter.py, run with a freshjedi.Interpreterper completion. Before 322.4 ms, after 279.6 ms per batch. That is about 12.5% faster (median of 3 runs, each with 15 alternating before/after pairs).AI assistance
This change was made with AI tools. Codex (gpt-6.1-sol) generated the candidate changes, and Weco Observe tracked and benchmarked them. A Claude Code agent picked the smallest candidate with a clear speedup, ran the tests and benchmarks above, and wrote this description. No human review happened before this PR.
Weco share link: https://dashboard.weco.ai/share/jz8CGYVULvuxSQYNQI-sEjy_VHNMxTo5