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

Perl_debug_log and Perl_error_log macro handles must be cached to avoid multiple evaluation #12602

Closed
p5pRT opened this issue Nov 22, 2012 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 22, 2012

Migrated from rt.perl.org#115858 (status was 'rejected')

Searchable as RT115858$

@p5pRT
Copy link
Author

p5pRT commented Nov 22, 2012

From @bulk88

Created by @bulk88

In gv_dump,
http​://perl5.git.perl.org/perl.git/blob/b3efb2487fa7bdef70865822dabaa2dc0000dde1​:/dump.c#l1165
, Perl_debug_log is a func call on my perl. Perl_debug_log is a macro
for Perl_PerlIO_stderr(my_perl), which is called 6 times in gv_dump
unnecessarily. Similar problems exist in ~1300 places (grepping the
interp, not any XS modules) in the interp as
"PerlIO_printf(Perl_debug_log". I suggest a PerlIO_printf_dbl (dbl=debug
log) that calls PerlIO_vprintf with the
Perl_debug_log/Perl_PerlIO_stderr(my_perl) call abstracted to
PerlIO_printf_dbl and not be in the caller wasting a couple bytes of L1
for an exceptional or rare branch. Debug channel stuff I don't think
deserved high performance. The other choice is to cache Perl_debug_log
at the start of the funcs that use it as an auto or at the start of a
block of a branch of stderr writes.

Perl_error_log macro is even worse than Perl_debug_log macro. It is
defined at
http​://perl5.git.perl.org/perl.git/blob/b3efb2487fa7bdef70865822dabaa2dc0000dde1​:/perl.h#l3651
and evaluates to this large tree of branches
______________________________________________________________
((my_perl->Istderrgv)
  && (((svtype) (((my_perl->Istderrgv))->sv_flags &
0xff)) == SVt_PVGV)
  && ((0 + ((my_perl->Istderrgv))->sv_u.svu_gp)->gp_io)
  && ((XPVIO *) (((0 +
((my_perl->Istderrgv))->sv_u.svu_gp)->gp_io))->sv_any)->
  xio_ofp ? ((XPVIO *) (((0 +
((my_perl->Istderrgv))->sv_u.svu_gp)->gp_io))->sv_any)->
  xio_ofp : Perl_PerlIO_stderr(my_perl))
______________________________________________________________

grepping says ~100 places for Perl_error_log. Sometimes its written 2 or
more times in the same func (
http​://perl5.git.perl.org/perl.git/blob/b3efb2487fa7bdef70865822dabaa2dc0000dde1​:/pp_ctl.c#l1664
), and of course the machine instructions are placed and executed twice
in a row (I checked that), compiler doesn't know that Perl_PerlIO_write
won't change PL_stderrgv.

Here is a list of all funcs on my perl build (no DEBUGGING/other special
debug macro defs are on), that call Perl_PerlIO_stderr more than once.
The number of times written, is the number of times that
Perl_PerlIO_stderr is referenced in that function.
___________________________________________________
Perl_call_list
Perl_call_list
Perl_debop
Perl_debop
Perl_debop
Perl_debop
Perl_debop
Perl_debop
Perl_debop
Perl_die_unwind
Perl_die_unwind
Perl_die_unwind
Perl_die_unwind
Perl_do_openn
Perl_do_openn
Perl_do_openn
Perl_dump_form
Perl_dump_form
Perl_dump_sub_perl
Perl_dump_sub_perl
Perl_dump_sub_perl
Perl_gv_dump
Perl_gv_dump
Perl_gv_dump
Perl_gv_dump
Perl_gv_dump
Perl_gv_dump
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
Perl_init_i18nl10n
perl_parse
perl_parse
perl_parse
perl_parse
Perl_re_op_compile
Perl_re_op_compile
perl_run
perl_run
Perl_runops_debug
Perl_runops_debug
Perl_sighandler
Perl_sighandler
S_my_exit_jump
S_my_exit_jump
S_regatom
S_regatom
S_regatom
S_regatom
S_regmatch
S_regmatch
win32_start_child
win32_start_child
________________________________________________

Some relevant git blame links

http​://perl5.git.perl.org/perl.git/blobdiff/65cec58980c279c041788ef30ee8617e63ab5229..bf49b05​:/perl.h

http​://perl5.git.perl.org/perl.git/blobdiff/dedcbb81b3c2f4f742df48d1d5918ae3c9eed4de..42de951​:/perl.h
http​://perl5.git.perl.org/perl.git/blobdiff/b38af7adab46822ec7c92d231d7fbb058dc22c4c..01bb7c6​:/perl.h
http​://perl5.git.perl.org/perl.git/blobdiff/aed17120f1d71c676ff756013d9027da2cec8e83..6b78add​:/perl.h

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.17.6:

Configured by Owner at Mon Nov 19 20:00:41 2012.

Summary of my perl5 (revision 5 version 17 subversion 6 patch blead 
2012-11-20.00:13:41 4c88d5e0740d796bf5064336d280bba72897f385 
v5.17.5-576-g4c88d5e) configuration:
  Snapshot of: 4c88d5e0740d796bf5064336d280bba72897f385
  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -GL -G7 
-DWIN32 -D_CONSOLE -DNO_STRICT  -DPERL_TEXTMODE_SCRIPTS 
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO 
-D_USE_32BIT_TIME_T',
    optimize='-MD -Zi -DNDEBUG -O1 -GL -G7',
    cppflags='-DWIN32'
    ccversion='13.10.6030', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf 
-ltcg  -libpath:"c:\perl517\lib\CORE"  -machine:x86'
    libpth="C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\lib"
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib 
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl517.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf -ltcg  -libpath:"c:\perl517\lib\CORE"  -machine:x86'

Locally applied patches:
    


@INC for perl 5.17.6:
    C:/perl517/site/lib
    C:/perl517/lib
    .


Environment for perl 5.17.6:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\perl517\bin;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\IDE;C:\Program Files\Microsoft Visual Studio .NET 
2003\VC7\BIN;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\Tools;C:\Program Files\Microsoft Visual Studio .NET 
2003\Common7\Tools\bin\prerelease;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Nov 13, 2017

From zefram@fysh.org

, Perl_debug_log is a func call on my perl. Perl_debug_log is a macro
for Perl_PerlIO_stderr(my_perl), which is called 6 times in gv_dump
unnecessarily.

I'm not worried about the performance of exception and debugging code.
This ticket should be closed.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Nov 13, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT p5pRT closed this as completed Nov 13, 2017
@p5pRT
Copy link
Author

p5pRT commented Nov 13, 2017

@cpansprout - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant