-
Notifications
You must be signed in to change notification settings - Fork 579
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
Statically cache the String value of g_internal_field for a small performance gain #4863
Conversation
a73ce43
to
5d3e50a
Compare
src/jsi/jsi_class.hpp
Outdated
@@ -490,7 +490,9 @@ class ObjectWrap { | |||
|
|||
static Internal* get_internal(JsiEnv env, const JsiObj& object) | |||
{ | |||
auto internal = object->getProperty(env, g_internal_field); | |||
static const auto js_internal_field = fbjsi::String::createFromAscii(env, g_internal_field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break on reload since it will continue to use the string from the old env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right yeah, good point. I guess there's no way round that? It's not a huge gain anyway so I'm happy to close this if that's best
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it a class-static like s_ctor with the same logic to set it on module load and reset on em teardown. This isnt a perfect solution because it assumes at most one env at a time, but it will at least work as well as the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in e32fc5b
Waiting on #4869 for lint to pass |
bf94457
to
a388208
Compare
e32fc5b
to
0b6099f
Compare
Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
1e159f6
to
1ed1d1e
Compare
Ignoring known failure on Android |
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
…formance gain (#4863) * Statically cache the String value of g_internal_field for a small performance gain * Fix lint * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Update src/jsi/jsi_class.hpp Co-authored-by: Mathias Stearn <redbeard0531@gmail.com> * Change to empty string for internal field name Co-authored-by: Mathias Stearn <redbeard0531@gmail.com>
What, How & Why?
This optimisation yields a small (~5% with Hermes disabled, ~2% with Hermes enabled) performance improvement with our benchmark suite, as it avoids the overhead of repeatedly creating the JSI String object.
☑️ ToDos
Compatibility
label is updated or copied from previous entrypackage.json
s (if updating internal packages)Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's: