Skip to content

perf(types): avoid double iteration in transform_dict_value_to_str - #3988

Open
ArulJerald wants to merge 1 commit into
apache:mainfrom
ArulJerald:optimization/optimize-transform-dict-value-to-str
Open

ArulJerald wants to merge 1 commit into
apache:mainfrom
ArulJerald:optimization/optimize-transform-dict-value-to-str

Conversation

@ArulJerald

Copy link
Copy Markdown

Summary

  • transform_dict_value_to_str iterated over dict.items() twice: once to
    validate no value is None, once more in a dict comprehension to convert
    values to strings. Combined into a single pass.
  • Renamed the parameter from dict to d so it no longer shadows the
    builtin type.

Closes #3987

Test plan

  • uv run pytest tests/test_types.py -k transform_dict_value_to_str
  • ruff check pyiceberg/types.py

Combine the None-validation and str-conversion loops over dict.items()
into a single pass, and rename the `dict` parameter to `d` to stop
shadowing the builtin.

Fixes apache#3987

@ebyhr ebyhr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is more of a cosmetic code quality fix than a meaningful perf win, but still worth having.

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.

Optimization: Avoid double iteration over dictionary items in transform_dict_value_to_str

2 participants