Skip to content

[ENH] Speed up first completion#399

Merged
peytondmurray merged 44 commits into
deshaw:masterfrom
peytondmurray:571-optimize-iter-modules
Aug 28, 2025
Merged

[ENH] Speed up first completion#399
peytondmurray merged 44 commits into
deshaw:masterfrom
peytondmurray:571-optimize-iter-modules

Conversation

@peytondmurray
Copy link
Copy Markdown
Collaborator

@peytondmurray peytondmurray commented Jul 25, 2025

This PR speeds up the first completion by

  • Removing some unnecessary list allocations
  • Pushing iteration over directory contents into compiled code. This avoids calling os.scandir, os.path.basename, and inspect.getmodulename on every directory entry.
  • An import caching system now tracks the state of any paths targeted by python's import machinery. Upon first completion, the modules available on each path are read using the new compiled extension before being stored in <user cache dir>/pyflyby/. Any subsequent completions (including in other ipython sessions) check the mtime of the path, and look for a corresponding file in <user cache dir>/pyflyby/. If a valid cache file is found, module names used for completion are read from the file rather than from the filesystem. Otherwise, the cache is rebuilt.
  • A function to force all import caches to be rebuilt is now available at pyflyby.rebuild_import_cache.

Other changes:

  • The build backend is now meson-python>=0.18.0
  • etc/ and libexec/ are now placed in <site-packages>/pyflyby instead of polluting other parts of the filesystem.
    I also removed some unused python 2 compatibility stuff adjacent to the code I was working on - if it's better to leave this for another PR I'll revert it.
  • appdirs and prompt_toolkit are now dependencies of pyflyby.

Closes #571.

@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from a411b33 to 0bbb60c Compare August 13, 2025 17:33
@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from 27b31c0 to d5e5f7b Compare August 14, 2025 05:50
@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from e8970c5 to 18a9101 Compare August 14, 2025 06:36
@krassowski
Copy link
Copy Markdown
Collaborator

krassowski commented Aug 15, 2025

During installation I encountered an error coming from mesonpy:

if licence_ and license.file:
                ^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'file'. Did you mean: 'title'?

It looks like the mesonpy version I get expects the old format (https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license).

I believe a lower bound on required mesonpy would be needed, or change in pyproject.toml to use the old format.

More details:

@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from 1c3f07b to d61b636 Compare August 22, 2025 19:34
@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from 232dc63 to c9a467c Compare August 22, 2025 22:35
@peytondmurray
Copy link
Copy Markdown
Collaborator Author

Note that due to the additional log messages this breaks some tests which check ipython output. I'll address these if the performance gains here are sufficient to warrant this change.

@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from ff1cbc9 to 7a45d5b Compare August 26, 2025 18:44
@peytondmurray peytondmurray force-pushed the 571-optimize-iter-modules branch from cbce19a to e81442d Compare August 26, 2025 20:33
@peytondmurray peytondmurray marked this pull request as ready for review August 26, 2025 23:39
Comment thread tests/test_interactive.py Outdated
@peytondmurray peytondmurray merged commit ee751d3 into deshaw:master Aug 28, 2025
8 checks passed
@peytondmurray peytondmurray deleted the 571-optimize-iter-modules branch August 28, 2025 05:48
peytondmurray added a commit to peytondmurray/pyflyby that referenced this pull request Sep 3, 2025
Comment thread pyproject.toml
"tomli; python_version<'3.11'",
"typing_extensions>=4.6; python_version<'3.12'",
'prompt_toolkit',
'epydoc',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please let me know why epydoc was added as a direct dependency?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it should be in test dependencies instead as it was in test_require before:

tests_require=['pexpect>=3.3', 'pytest', 'epydoc', 'rlipython', 'requests'],

Cc @peytondmurray in case if there was a reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants