Skip to content

Initialise tables instead of calculating them at run time#128

Closed
adrianmay wants to merge 5 commits intotahoe-lafs:masterfrom
adrianmay:inittables
Closed

Initialise tables instead of calculating them at run time#128
adrianmay wants to merge 5 commits intotahoe-lafs:masterfrom
adrianmay:inittables

Conversation

@adrianmay
Copy link

@adrianmay adrianmay commented Mar 17, 2025

In fec.c there are four tables whose contents are always the same. (These should not be confused with another table that depends on n and k.)

Their contents are currently calculated when fec_init is called. It's hard to make sure this happens exactly once. It's also inefficient and rules out loading the tables into RAM on demand and discarding them when not in use.

This PR solves this by introducing a file tables.c in which the tables are initialised. That file was generated by a small program in write.c which calls fec_init and dumps the tables in C syntax.

write.c is not a pre-build step. It's been used once to generate tables.c which is in source control. write.c and the Makefile that runs it into tables.c is included in source control for reference only.

We could slightly shrink the library by moving the logic that calculates the tables into write.c but the MR is presented in the present form to provide assurance that the calculation has not changed.

After this, (contrary to what I said in ticket #126) it will still be necessary to convert the haskell wrapper to return IO, which forces a major version bump, in which case we might as well remove initialise. The reason is that fec_encode and fec_decode return void but populate a passed buffer. Haskell could lazily skip their wrappers unless they return IO (). This will be done in a subsequent PR.

@adrianmay adrianmay marked this pull request as draft March 18, 2025 09:36
@adrianmay
Copy link
Author

Superseded by #130 and #131, so closing.

@adrianmay adrianmay closed this Mar 18, 2025
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