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

Only deep_symbolize_keys when needed #588

Merged

Conversation

paarthmadan
Copy link
Contributor

Following the tentative changes proposed in #587 and #583, we should avoid performing deep_symbolize_keys on the translations when it's unnecessary.

This PR currently includes changes from #587 to showcase usage. I'll update it with changes from #583 too, if and when that merges.

This PR returns an additional attribute from the load_* methods to provide a flag of whether the keys have been symbolized at parse time. If so, we skip deep_symbolize_keys. This is a performance optimization that helps avoid traversing the object graph when we don't need to.

I suppose we can also inject a magic key in the locale hash indicating whether keys are symbolized already, but I felt this approach was less intrusive.

@radar
Copy link
Collaborator

radar commented Dec 12, 2021

I looked at that failing spec but it seems to be a flaky one, nothing caused by your changes here.

changes LGTM, will probably merge tomorrow morning or Tuesday, depending on my schedules

JSON.load_file being defined implies that symbolize_names and freeze
options are supported at parse time. We use this as a best effort
feature test.
When loading certain translations from file, they can be parsed into their Symbol representation. It is wasteful to traverse the entire object graph in these cases.
@paarthmadan paarthmadan force-pushed the pm/only-deep-symbolize-keys-when-needed branch from a85f2ba to cbca32e Compare December 13, 2021 19:19
@paarthmadan
Copy link
Contributor Author

paarthmadan commented Jan 21, 2022

@radar Could this PR, along with #583 and #587 be reconsidered? I've addressed all of your feedback. Thanks!

@radar
Copy link
Collaborator

radar commented Jan 24, 2022 via email

@radar radar merged commit 2307c7c into ruby-i18n:master Jan 25, 2022
@paarthmadan paarthmadan deleted the pm/only-deep-symbolize-keys-when-needed branch January 26, 2022 16:00
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.

None yet

2 participants