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

Use Arrays instead of Language-Records for index-functions #68

Open
LorisSigrist opened this issue Apr 9, 2024 — with Linear · 0 comments
Open

Use Arrays instead of Language-Records for index-functions #68

LorisSigrist opened this issue Apr 9, 2024 — with Linear · 0 comments
Assignees

Comments

Copy link
Member

LorisSigrist commented Apr 9, 2024

Context

This is an optimization that was pointed out to me by a dev from Galaxus.ch

We currently do a record-lookup for the language-specific message function when evaluating index-message functions

export const my_message = () => {
  return {
    en: en.my_message,
    de: de.my_message
  }[languageTag()]()
}

Proposal

If we instead had a canonical order for the languages we could do an array-lookup instead. This would save 3 chars per language per message.

export const my_message = () => [en.my_message, de.my_message][languageTagIdx()]()

If we have 5 languages on average, that's 15bytes per message, so on a page with 50 messages that would be over half a kb on a normal page. That's over 20%.

@LorisSigrist LorisSigrist self-assigned this Apr 9, 2024
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

1 participant