Skip to content

Implement InlineArray for lookup table optimization #2

Description

@zamderax

Description

Replace the current [Polynomial] lookup table with Swift 6.2's InlineArray<256, Polynomial> for better performance and memory layout.

Background

The CRC lookup table currently uses a regular Swift Array with 256 elements. Swift 6.2 introduces InlineArray which provides better performance characteristics for fixed-size arrays by storing elements inline rather than on the heap.

TODO Comment Reference

There's already a TODO comment in the code at line 196-197 in CyclicRedundancyCheck.swift:

// TODO: Replace with InlineArray<256> down the line 
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0453-vector.md

Implementation Requirements

  1. Add conditional compilation to use InlineArray<256, Polynomial> when Swift 6.2+ is available
  2. Fall back to regular Array<Polynomial> for backward compatibility
  3. Update Package.swift to enable the experimental InlineArray feature
  4. Ensure all tests continue to pass
  5. Verify performance improvements

Considerations

  • InlineArray is currently experimental and may require specific Swift toolchain versions
  • Need to maintain backward compatibility with older Swift versions
  • Should verify the feature is actually available at compile time before using it

Expected Benefits

  • Improved cache locality for lookup table access
  • Reduced memory allocation overhead
  • Better performance for CRC calculations

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions