[perf][1/5] Replace IValue::toString()->string() with IValue::toStringRef() (#85437)

Summary: `IValue::toString()` creates a `new c10::intrusive_ptr` (like `std::shared_ptr`) and `->string()` immediately accesses it, creating an atomic reference increment/decrement. We can skip both of these operations by calling `IValue::toStringRef()`.

Test Plan: CI

Reviewed By: jaybean-dev

Differential Revision: D39605242

Pull Request resolved: https://github.com/pytorch/pytorch/pull/85437
Approved by: https://github.com/jfix71
This commit is contained in:
Alex Beloi
2022-09-23 23:36:57 +00:00
committed by PyTorch MergeBot
parent ea81138bd6
commit a38e43e936
19 changed files with 38 additions and 40 deletions

View File

@ -303,7 +303,7 @@ facebook::jni::local_ref<JIValue> JIValue::newJIValueFromStringDict(
facebook::jni::alias_ref<JIValue::javaobject>>::create();
for (auto& pair : dict) {
jmap->put(
facebook::jni::make_jstring(pair.key().toString()->string()),
facebook::jni::make_jstring(pair.key().toStringRef()),
JIValue::newJIValueFromAtIValue(pair.value()));
}
return jMethodDictStringKey(JIValue::javaClassStatic(), jmap);