Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Ignoring that I don't know what "GLR and SLR" are -- and you do not bother to explain them -- I'd be interested to see proof of that "much faster". Faster I have no doubts, but much faster?

See "TlsGetValue was implemented with speed as the primary goal."

And I counter that assertion with: speed isn't everything.

My new motto, death by a thousand cuts.

Win XP TlsGetValue has 3 branches in asm. 1 branch on the found value path. On found value path, other than mandatory stack frame maintenance, deref FS Register, deref c stack index val, cmp index val to const, cond jump, and TEB in regular register + offset with const 0 (setlasterror = 0), move TEB in regular register+index reg+ SIB encoded constant to eax, return. A total of 11 machine opcodes executed, stack frame maintenance included. That is also ignoring the SetLastError and GetLastError done by Perl before and after TlsGetValue. Now time for some real world numbers.
void CxtSpeed() PREINIT: LARGE_INTEGER start; LARGE_INTEGER end; int i; PPCODE: QueryPerformanceCounter(&start); for(i=0; i < 1000000000; i++){ no_cxt(); } QueryPerformanceCounter(&end); printf("no cxt %I64u\n", end.QuadPart-start.QuadPart); QueryPerformanceCounter(&start); for(i=0; i < 1000000000; i++){ cxt(aTHX); } QueryPerformanceCounter(&end); printf("cxt %I64u\n", end.QuadPart-start.QuadPart);
//separate compiland/obj file #define PERL_NO_GET_CONTEXT #include <EXTERN.h> #include <perl.h> #include <XSUB.h> __declspec(dllexport) int no_cxt(){ dTHX; return ((int) my_perl) >> 1; } __declspec(dllexport) int cxt(pTHX){ return ((int) my_perl) >> 1; }
#in makefile.pl hash to WriteMakefile FUNCLIST => ['no_cxt', 'cxt'], dynamic_lib => { OTHERLDFLAGS => ' noopt.obj ' , INST_DYNAMIC_DEP => 'noopt.obj' },
Make sure to check disassembly to make it wasn't all inline optimized away. cxt() loop was completely removed in my 1st try.
C:\Documents and Settings\Owner\Desktop\cpan libs\lxs>perl -MLocal::XS + -e "Local:: XS::CxtSpeed();" no cxt 48160819 cxt 11096124 C:\Documents and Settings\Owner\Desktop\cpan libs\lxs>
Whole script took about 5-8 seconds. 1 Perl_get_context took 4.3 times more time than passing it on the C stack and of course everything tested fit L1 the whole time. I would much rather have my_perl on the C stack or in a register (compiler's choice) than call Perl_get_context half a dozen or more times in every Perl C function. If you want to know why TlsGetValue is never optimized away to inline assembly, ask MS. I didn't write Kernel32.

I'm surprised it only took 4 times longer. GetLastError is 3 opcodes, stack frame maintenance included. SetLastError is 8 opcode, stack frame maintenance included. TlsGetValue was 11 opcodes, stack frame maintenance included. Perl_get_context is 13 opcodes, no branches, stack frame maintenance included. 3 opcodes for no_cxt, stack frame maintenance included. Total of 38 opcodes for no_cxt. A total of 3 opcodes for cxt(), stack frame maintenance included. So, no_cxt took 12.6 times more opcodes than cxt, yet only 4.3 times more time. Did my superscalar Core 2 eliminate all those function calls to one function call with IPO when it recompiled x86 asm to microop asm or branch predictor + cache dirty flag checking removed the code? IDK, but interesting numbers anyway. In any case my_perl in a register/c stack wins.

Which is why I think your post would have been better directed at the alternative you suggested.

Should I delete my post and post it to the other post?
GObject and Perl's GC systems have many similarities. ... I am saying that would be a bad choice.

Then why mention it? No one else did.

The OP was vague and didn't concisely explain anything, so I had to consult with my crystal ball that I got at the pound shop made from lead wiring, chip board and bitumen, to read the OP's mind. My crystal ball said he is using Perl in a DLL that doesn't link with Perl but includes Perl's headers for Perl's GC. Should I use my O'Reilly brand tarot cards in the future?

Aren't you just as guilty of misdirection by bringing it up and leaving it hanging as the guy that suggested: "you'll be fine so long as you don't use threads"? Which seems to be the focus of your posts.

I gave an answer
Someone who didn't read the manual will think they can use Perl C data structures without a "useless" Perl around instead of GObject
If you read the manual (perlapi/perlguts/illguts/perlembed/perlxs), you will know that using Perl without an initialized interp is not supported by Perl.

In reply to Re^10: Use perl type without perl by bulk88
in thread Use perl type without perl by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (6)
    As of 2014-09-17 07:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (62 votes), past polls