Skip to content

Commit 5f1996a

Browse files
generatedunixname1395027625275998meta-codesync[bot]
authored andcommitted
Speed up failedDeferredCompileShim via lazy arg alloc and fast return-type check
Reviewed By: DenisYaroshevskiy Differential Revision: D116733369 fbshipit-source-id: 1ea9e4e6328b18f49f325cd55e1fca6fde429fff
1 parent f0e6be7 commit 5f1996a

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

cinderx/Jit/jit_rt.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <cmath>
4646
#include <span>
4747
#include <type_traits>
48+
#include <vector>
4849

4950
using namespace cinderx;
5051
using namespace cinderx::jit;
@@ -1610,20 +1611,21 @@ StaticCallReturn failedDeferredCompileShim(PyObject** args) {
16101611
// ...
16111612

16121613
PyObject** dest_args;
1613-
auto final_args = std::make_unique<PyObject*[]>(total_args);
1614+
std::vector<PyObject*> final_args;
16141615
int cc_reg_args = codegen::ARGUMENT_REGS.size();
16151616

16161617
if (total_args < cc_reg_args) {
16171618
// no gap in args to worry about
16181619
dest_args = args + 1;
16191620
} else {
1621+
final_args.resize(total_args);
16201622
for (int i = 0; i < cc_reg_args - 1; i++) {
16211623
final_args[i] = args[i + 1];
16221624
}
16231625
for (int i = cc_reg_args - 1; i < total_args; i++) {
16241626
final_args[i] = args[i + 3];
16251627
}
1626-
dest_args = final_args.get();
1628+
dest_args = final_args.data();
16271629
}
16281630

16291631
_PyTypedArgsInfo* arg_info = getContext()->findFunctionPrimitiveArgInfo(func);
@@ -1678,11 +1680,8 @@ StaticCallReturn failedDeferredCompileShim(PyObject** args) {
16781680
// If we are supposed to be returning a primitive, it needs unboxing because
16791681
// our caller expected this to be a static->static direct invoke, we just
16801682
// failed to JIT the callee.
1681-
int optional, exact;
1682-
PyTypeObject* ret_type = _PyClassLoader_ResolveType(
1683-
_PyClassLoader_GetReturnTypeDescr(func), &optional, &exact);
1684-
int ret_code = _PyClassLoader_GetTypeCode(ret_type);
1685-
Py_DECREF(ret_type);
1683+
int ret_code = _PyClassLoader_ResolvePrimitiveType(
1684+
_PyClassLoader_GetReturnTypeDescr(func));
16861685
if (ret_code != TYPED_OBJECT) {
16871686
// we can always unbox to 64-bit, the JIT will just ignore the higher bits.
16881687
// This means that overflow here will give weird results, but overflow in

0 commit comments

Comments
 (0)