Skip to content

perf(table): import the expression parser lazily - #4012

Merged
Fokko merged 1 commit into
apache:mainfrom
kuldeeepy:perf-lazy-import-expression-parser
Sep 24, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
kuldeeepy:perf-lazy-import-expression-parser

Conversation

@kuldeeepy

Copy link
Copy Markdown
Contributor

Rationale for this change

pyiceberg.table imports pyiceberg.expressions.parser at module level, but only _parse_row_filter uses it, when the row filter is a string. Importing it pulls in pyparsing, and through pyparsing.testing also unittest, argparse and difflib. So every import pyiceberg.table and load_catalog pays for it, even when no string filter is used.

This moves the import into _parse_row_filter, the same way the file already imports ArrowScan locally. After the change pyparsing is no longer loaded by from pyiceberg.catalog import load_catalog, and the number of loaded modules goes from 389 to 361. On my machine that import takes about 6% less CPU time.

Are these changes tested?

Covered by the existing parser and row filter tests. make lint and make test pass.

Are there any user-facing changes?

No.

This change was made with AI assistance (Claude Code). I checked the import paths and ran the measurements and tests myself.

The parser is only used by _parse_row_filter for string row filters,
but importing it at module level pulls in pyparsing (and unittest,
argparse and difflib through pyparsing.testing) on every
`import pyiceberg.table` and `load_catalog`.

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reasonable change, thanks @kuldeeepy

@Fokko
Fokko added this pull request to the merge queue Sep 24, 2026
Merged via the queue into apache:main with commit f7dcc3d Sep 24, 2026
21 checks passed
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.

2 participants