Skip to content

Commit 75acd14

Browse files
richardleachxenu
authored andcommitted
Make newSV_type an inline function
When a new SV is created and upgraded to a type known at compile time, uprooting a SV head and then using the general-purpose upgrade function (sv_upgrade) is clunky. Specifically, while uprooting a SV head is lightweight (assuming there are unused SVs), sv_upgrade is too big to be inlined, contains many branches that can logically be resolved at compile time for known start & end types, and the lookup of the correct body_details struct may add CPU cycles. This commit tries to address that by making newSV_type an inline function and including only the parts of sv_upgrade needed to upgrade a SVt_NULL. When the destination type is known at compile time, a decent compiler will inline a call to newSV_type and use the type information to throw away all the irrelevant parts of the sv_upgrade logic. Because of the spread of type definitions across header files, it did not seem possible to make the necessary changed inside sv.h, and so a new header file (sv_inline.h) was created. For the inlined function to work outside of sv.c, many definitions from that file were moved to sv_inline.h. Finally, in order to also benefit from this change, existing code in sv.c that does things like this: SV* sv; new_SV(sv); sv_upgrade(sv, SVt_PV) has been modified to read something like: SV* sv = newSV_type(SVt_PV);
1 parent 4f16878 commit 75acd14

File tree

8 files changed

+525
-370
lines changed

8 files changed

+525
-370
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,6 +5569,7 @@ scope.h Scope entry and exit header
55695569
SECURITY.md Add Security Policy for GitHub
55705570
sv.c Scalar value code
55715571
sv.h Scalar value header
5572+
sv_inline.h Perl_newSV_type and required defs
55725573
t/base/cond.t See if conditionals work
55735574
t/base/if.t See if if works
55745575
t/base/lex.t See if lexical items work

embed.fnc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ Apd |SV* |newSVrv |NN SV *const rv|NULLOK const char *const classname
15191519
ApMbdR |SV* |newSVsv |NULLOK SV *const old
15201520
AmdR |SV* |newSVsv_nomg |NULLOK SV *const old
15211521
AdpR |SV* |newSVsv_flags |NULLOK SV *const old|I32 flags
1522-
ApdR |SV* |newSV_type |const svtype type
1522+
ApdiR |SV* |newSV_type |const svtype type
15231523
ApdR |OP* |newUNOP |I32 type|I32 flags|NULLOK OP* first
15241524
ApdR |OP* |newUNOP_AUX |I32 type|I32 flags|NULLOK OP* first \
15251525
|NULLOK UNOP_AUX_item *aux
@@ -3171,7 +3171,7 @@ S |STRLEN |sv_pos_b2u_midway|NN const U8 *const s|NN const U8 *const target \
31713171
S |void |assert_uft8_cache_coherent|NN const char *const func \
31723172
|STRLEN from_cache|STRLEN real|NN SV *const sv
31733173
ST |char * |F0convert |NV nv|NN char *const endbuf|NN STRLEN *const len
3174-
S |SV * |more_sv
3174+
Cp |SV * |more_sv
31753175
S |bool |sv_2iuv_common |NN SV *const sv
31763176
S |void |glob_assign_glob|NN SV *const dsv|NN SV *const ssv \
31773177
|const int dtype
@@ -3180,7 +3180,7 @@ S |void |anonymise_cv_maybe |NN GV *gv|NN CV *cv
31803180
#endif
31813181

31823182
: Used in sv.c and hv.c
3183-
po |void * |more_bodies |const svtype sv_type|const size_t body_size \
3183+
Cpo |void * |more_bodies |const svtype sv_type|const size_t body_size \
31843184
|const size_t arena_size
31853185
EXpR |SV* |get_and_check_backslash_N_name|NN const char* s \
31863186
|NN const char* e \

embed.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@
881881
#define dump_mstats(a) Perl_dump_mstats(aTHX_ a)
882882
#define get_mstats(a,b,c) Perl_get_mstats(aTHX_ a,b,c)
883883
#endif
884+
#if defined(PERL_IN_SV_C)
885+
#define more_sv() Perl_more_sv(aTHX)
886+
#endif
884887
#if defined(PERL_USE_3ARG_SIGHANDLER)
885888
#define csighandler Perl_csighandler
886889
#endif
@@ -1932,7 +1935,6 @@
19321935
#define find_uninit_var(a,b,c,d) S_find_uninit_var(aTHX_ a,b,c,d)
19331936
#define glob_2number(a) S_glob_2number(aTHX_ a)
19341937
#define glob_assign_glob(a,b,c) S_glob_assign_glob(aTHX_ a,b,c)
1935-
#define more_sv() S_more_sv(aTHX)
19361938
#define not_a_number(a) S_not_a_number(aTHX_ a)
19371939
#define not_incrementable(a) S_not_incrementable(aTHX_ a)
19381940
#define ptr_table_find S_ptr_table_find

perl.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,6 @@ Use L</UV> to declare variables of the maximum usable size on this platform.
12521252
(((U64)(x) & UINT64_C(0xff00000000000000)) >> 56) ))
12531253
# endif
12541254

1255-
/* The old value was hard coded at 1008. (4096-16) seems to be a bit faster,
1256-
at least on FreeBSD. YMMV, so experiment. */
1257-
#ifndef PERL_ARENA_SIZE
1258-
#define PERL_ARENA_SIZE 4080
1259-
#endif
1260-
12611255
/* Maximum level of recursion */
12621256
#ifndef PERL_SUB_DEPTH_WARN
12631257
#define PERL_SUB_DEPTH_WARN 100
@@ -7160,6 +7154,7 @@ cannot have changed since the precalculation.
71607154
START_EXTERN_C
71617155

71627156
# include "inline.h"
7157+
# include "sv_inline.h"
71637158

71647159
END_EXTERN_C
71657160

proto.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,9 +2482,11 @@ PERL_CALLCONV OP* Perl_newSVREF(pTHX_ OP* o)
24822482
#define PERL_ARGS_ASSERT_NEWSVREF \
24832483
assert(o)
24842484

2485-
PERL_CALLCONV SV* Perl_newSV_type(pTHX_ const svtype type)
2485+
#ifndef PERL_NO_INLINE_FUNCTIONS
2486+
PERL_STATIC_INLINE SV* Perl_newSV_type(pTHX_ const svtype type)
24862487
__attribute__warn_unused_result__;
24872488
#define PERL_ARGS_ASSERT_NEWSV_TYPE
2489+
#endif
24882490

24892491
PERL_CALLCONV SV* Perl_newSVavdefelem(pTHX_ AV *av, SSize_t ix, bool extendible)
24902492
__attribute__warn_unused_result__;
@@ -6461,7 +6463,7 @@ STATIC bool S_glob_2number(pTHX_ GV* const gv);
64616463
STATIC void S_glob_assign_glob(pTHX_ SV *const dsv, SV *const ssv, const int dtype);
64626464
#define PERL_ARGS_ASSERT_GLOB_ASSIGN_GLOB \
64636465
assert(dsv); assert(ssv)
6464-
STATIC SV * S_more_sv(pTHX);
6466+
PERL_CALLCONV SV * Perl_more_sv(pTHX);
64656467
#define PERL_ARGS_ASSERT_MORE_SV
64666468
STATIC void S_not_a_number(pTHX_ SV *const sv);
64676469
#define PERL_ARGS_ASSERT_NOT_A_NUMBER \

0 commit comments

Comments
 (0)