Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy speed-up possible? #100

Open
sergiocorreia opened this issue May 19, 2023 · 1 comment
Open

Easy speed-up possible? #100

sergiocorreia opened this issue May 19, 2023 · 1 comment

Comments

@sergiocorreia
Copy link

sergiocorreia commented May 19, 2023

Hi Winston,

When running font_import() I get the message "Importing fonts may take a few minutes" and it indeed takes quite a while even if all fonts are already registered.

It seems this is because we are essentially running an O^2 task as every time we try to add a new font we re-run fonttable(), which reloads the underlying CSV file entirely.

Would it be easier to do something like fonts <- fonttable() right before we start the loop on line 78?

Thanks!

PS: Sorry for the lack of PRs; I'm quite new using R, so not entirely sure what I'm doing in that sense

@wch
Copy link
Owner

wch commented May 20, 2023

@sergiocorreia I haven't looked at this code in a long time, but I think you may be right that it doesn't have to read the table each time.

That said, I suspect that the time to read the CSV file is minuscule compared to the other stuff that happens in that loop. For example, if you run this, I think it should be quite fast (I don't have extrafont set up on my current computer so I haven't tested myself):

library(extrafont)
system.time({
  for (i in 1:100) {
    fonttable()
  } 
})

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

No branches or pull requests

2 participants