Speed up formatting HUGEINT, UHUGEINT and DECIMAL(38) as strings
The Issue & Context
Before this PR, formatting HUGEINT, UHUGEINT, and DECIMAL(38) values to strings was slow because it performed a costly 128-bit division for every single digit, causing significant delays especially for large numbers.
Root Cause Analysis
The existing implementation used a naive bit-by-bit 128-bit division approach in the formatting function, which meant that for UHUGEINT values, the division was repeated once per digit, leading to excessive computational overhead when converting large numbers to strings.
Solution Strategy & Architectural Pattern
This PR replaces the per-digit 128-bit division with a more efficient method that processes 19 digits at a time using a single 128-by-64-bit division, significantly reducing the number of division operations needed during formatting and speeding up string conversion across HUGEINT, UHUGEINT, and DECIMAL(38) types.
Key Takeaway for Contributors
When converting large numeric types to strings, batching digit extraction using wider divisions can drastically reduce computation compared to per-digit division, highlighting the importance of choosing division granularity to optimize performance in numeric formatting.