#Recommendation on efficiently encoding font metrics in Elixir

1 messages · Page 1 of 1 (latest)

keen igloo
#

I am in the process of porting text measurement logic to our backend. (Related to rendering PDFs.)

I'm looking for suggestions on how someone might encode the data below (specifically the lines I'm sharing):
https://github.com/Hopding/standard-fonts/blob/master/font_metrics/Helvetica.afm#L25-L341

Example line:

C 32 ; WX 278 ; N space ; B 0 0 0 0 ;

Each key-value pair is separated by a semicolon. Because I may be measuring many lines/paragraphs of text, it needs to be fast to lookup by the first field (char code).

I was thinking maybe code-generation would be worth it in this case?

minor flicker
#

Iirc maps/structs with less than 32 keys are pretty fast

#

And if that won't be sufficient, then a NIF would be faster still. So why bother with code generation?

cobalt flame
#

If you have a lot of these and you want to make it small and fast, then records are probably the best approach there

keen igloo
#

Thanks for the feedback. Perhaps it's overkill, but I ended up copying how the timezone libraries implement this. I dump the font data to a .term.gz file and load it into ets.

We may need to add more font information so I wanted to avoid adding to the compile time