Skip to content

Conversation

@clipperhouse
Copy link
Owner

@clipperhouse clipperhouse commented Nov 24, 2025

asciiWidths was a 256-byte (int8) array for fast lookups. This PR uses a more compact representation, 256 bits as 4 uint64’s. In turn, the asciiWidth func masks and shifts to extract the same values as the array lookup.

asciiProperty func does the same, but the inverse, because the _Default enum happens to be 0 and _Zero_Width happens to be 1. The asciiProperties lookup array was eliminated, leaving only the asciiWidths integers.

So, 2 × 256 bytes → 32 bytes of table storage, a 16× reduction. A bit more cache-friendly, one hopes.

Performance looks about the same, maybe faster, but likely within any margin of error.

A tiny little bit faster, but smaller in memory
Copilot AI review requested due to automatic review settings November 24, 2025 04:01
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 optimizes ASCII character lookup tables by replacing two 256-byte arrays with a compact bitmask representation using four uint64 values (32 bytes total), achieving a 16× memory reduction. The optimization maintains the same functionality through bit manipulation operations instead of direct array indexing.

Key Changes

  • Replaced asciiWidths and asciiProperties lookup arrays with a single asciiWidths bitmask array of 4 uint64s
  • Implemented asciiWidth() and asciiProperty() functions that use bit shifting and masking to extract values from the bitmask
  • Updated all call sites in width.go to use the new functions instead of array lookups
  • Added comprehensive test coverage for the new bitmask-based lookup functions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tables.go Replaces lookup arrays with compact bitmask representation and implements bit manipulation functions for value extraction
tables_test.go Adds comprehensive test coverage for the new bitmask functions, including edge cases and enum invariant validation
width.go Updates all call sites to use new asciiWidth() and asciiProperty() functions; minor variable extraction refactoring

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

@clipperhouse
Copy link
Owner Author

Too complicated, simplified in #12 .

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