in reply to Re^2: Why is const x const not a const?
in thread Why is const x const not a const?

Then why does «sprintf '%-100000s', 'a'» create a string of 100,000 characters at compile-time like «"a" x 100_000» currently does at run-time.

And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

If something could fold into something that's considered too large, that particular folding should be prevented, not all foldings of that operator.

Replies are listed 'Best First'.
Re^4: Why is const x const not a const?
by moritz (Cardinal) on Jan 23, 2012 at 09:50 UTC
    And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

    It does? How can you tell?

    Neither B::Deparse nor B::Concise seem to indicate that, nor the compile time memory consumption.

      It shows up as const AV in the opcode tree.

      You can prove the list is flattened once using

      for (1..2) { for ((), 4..8) { say $_++; } }

      Update: Added missing parens.

        It shows up as const AV in the opcode tree.

        You can prove the list is flattened once using

        I see the 1 & 2, and 4 & 8 as consts, but I'm also seeing what look to me like two loops. Perhaps you can interpret it better?:

        c:\test>perl -MO=Concise for (1..2) { for (4..8) { say $_++; } } ^Z t <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 4 -:1) v:{ ->3 s <2> leaveloop vK/2 ->t 7 <{> enteriter(next->p last->s redo->8) lKS/8 ->q - <0> ex-pushmark s ->3 - <1> ex-list lK ->6 3 <0> pushmark s ->4 4 <$> const[IV 1] s ->5 5 <$> const[IV 2] s ->6 6 <#> gv[*_] s ->7 - <1> null vK/1 ->s r <|> and(other->8) vK/1 ->s q <0> iter s ->r - <@> lineseq vKP ->- 8 <;> nextstate(main 2 -:2) v:{ ->9 o <2> leaveloop vK/2 ->p d <{> enteriter(next->l last->o redo->e) lKS/8 ->m - <0> ex-pushmark s ->9 - <1> ex-list lK ->c 9 <0> pushmark s ->a a <$> const[IV 4] s ->b b <$> const[IV 8] s ->c c <#> gv[*_] s ->d - <1> null vK/1 ->o n <|> and(other->e) vK/1 ->o m <0> iter s ->n - <@> lineseq vKP ->- e <;> nextstate(main 1 -:3) v:{ ->f k <1> preinc[t7] vK/1 ->l j <1> entersub[t6] sKRMS/NO(),TARG ->k f <0> pushmark s ->g - <1> ex-rv2sv sKM/1 ->h g <#> gvsv[*_] s ->h h <$> method_named[PV "say"] s ->i i <1> rv2cv /NO() ->j l <0> unstack v ->m p <0> unstack v ->q - syntax OK

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re^4: Why is const x const not a const?
by BrowserUk (Patriarch) on Jan 23, 2012 at 10:10 UTC
    And then there's 1..100_000 that creates an array and 100,000 scalars at compile-time.

    Really? Can you demonstrate that?

    Because I see no evidence for it:

    c:\test>perl -le"++$n for 1..1e2; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 7500 Console 1 5 +,716 K c:\test>perl -le"++$n for 1..1e3; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 3676 Console 1 5 +,712 K c:\test>perl -le"++$n for 1..1e4; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 6048 Console 1 5 +,732 K c:\test>perl -le"++$n for 1..1e5; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 5648 Console 1 5 +,720 K c:\test>perl -le"++$n for 1..1e6; system qq[tasklist /nh /fi \"pid eq +$$\"] " perl.exe 8620 Console 1 5 +,736 K

    Whilst the memory usage varies a little, it sometime goes down a few k when the notional size of this array increases by an order of magnitude?

    Conversely, if you explicitly create an array of that size, the memory requirement increases by 100MB as expected:

    c:\test>perl -le"@a = 1 .. 1e6; system qq[tasklist /nh /fi \"pid eq $$ +\"] " perl.exe 2664 Console 1 109 +,576 K

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      > Because I see no evidence for it:

      Not surprising

      for (START .. STOP) { }

      is magically optimized into an iterator to avoid building the list.

      But if you try

      for (reverse START .. STOP) { }

      instead, you will see the memory consumption, because that optimization is (unfortunately) missing here.

      Cheers Rolf