Skip to content

Comments

Avoid Decimal objects in number_to_string#1

Merged
bbayles merged 3 commits intomasterfrom
no-decimal-format
Jan 19, 2026
Merged

Avoid Decimal objects in number_to_string#1
bbayles merged 3 commits intomasterfrom
no-decimal-format

Conversation

@bbayles
Copy link
Collaborator

@bbayles bbayles commented Jan 13, 2026

This PR updates playlist serialization such that it avoids creating Python Decimal objects.

We want this input and output behavior:

25 -> '25'
25.0 -> '25'
25.1 -> '25.1'
0.000011 -> '0.000011'

We never want exponential notation, even for very small numbers. We do want integer values to look like integers, even if they come in as floats.

This PR:

  • Formats the input number as a fixed point number with 6 places after the decimal
  • Strips off trailing 0s
  • Strips off trailing decimal points

The performance is 3x better this way. All existing tests pass, and our library of ~900 playlists from the wild show no change.

CC: @wurlced, @bendpham

@bbayles bbayles requested a review from Copilot January 13, 2026 21:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the performance of playlist serialization by replacing Decimal-based number formatting with a simpler string formatting approach that avoids creating Decimal objects.

Changes:

  • Removed the decimal module import and refactored number_to_string() to use Python's built-in format() function
  • Updated number_to_string() to accept a format specifier parameter for flexibility
  • Simplified the StreamInfo.__str__() method to use the updated number_to_string() for frame rate formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bbayles bbayles merged commit d5d5256 into master Jan 19, 2026
13 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.

1 participant