I would like to rase it again, because I started to check it, and looks like I 
found a problem I meet before:

it is about extracting `seq` from `[string, seq[int]]Table`

The code:
    
    
    import std/tables
    import std/monotimes
    import std/times
    import std/sequtils
    
    proc main() =
      var t = initTable[int, seq[int]](1000)
      for i in 0..99:
        t[i] = newSeqWith(1_000_000, 1)
      
      let fakeSeq = newSeqWith(1_000_000, 1)
      
      echo "start"
      let start = getMonotime()
      var cnt = 0
      for i in 1..10000:
        for x in t[i mod 100]:
          cnt += x
      echo cnt, " in ", (getMonotime()-start).inMilliseconds
    
    main()
    
    
    
    Run

takes ~16s

if I replace `t[i mod 100]` with `fakeSeq` . Not 100% sure that it is correct 
replacement to check the problem.

Then is takes just ~4s

perf shows the following:
    
    
    -   69.71%     0.00%  a        a                     [.] eqcopy___a_u151 
(inlined)                                     ▒
       - eqcopy___a_u151 (inlined)                                              
                                           ▒
          - setLen__a_u168                                                      
                                           ▒
             - newSeqPayload                                                    
                                           ▒
                - alignedAlloc0__system_u1947 (inlined)                         
                                           ▒
                - allocShared0Impl__system_u1776 (inlined)                      
                                           ▒
                   - 13.15% zeroMem__system_u1742 (inlined)                     
                                           ▒
                        nimZeroMem (inlined)                                    
                                           ▒                    
nimSetMem__systemZmemory_u7 (inlined)                                           
                   ▒                    0x7f108ff41c4a                          
                                                           ▒+   35.71%    
22.55%  a        a                     [.] setLen__a_u168
    
    
    Run

I do not see `[]` in front of it like I saw in the related_post_gen, but I see 
the eqcopy which looks like copy of the seq

I am pretty sure I heard something about it on the forum or github, but not 
sure where.

I am not 100% that it is equivalent of the initial code, because in initial 
code I saw the following:
    
    
    -   58.26%     0.00%  related  related           [.] 
countTaggedPost__related_u2205 (inlined)                          ▒
       - countTaggedPost__related_u2205 (inlined)                               
                                           ▒
          - 26.41% X5BX5D___related_u2269 (inlined)                             
                                           ▒
             - 25.39% eqcopy___related_u252 (inlined)                           
                                           ▒
                - setLen__related_u269 (inlined)                                
                                           ▒
                   - 10.62% prepareSeqAdd                                       
                                           ▒
                      - newSeqPayload (inlined)                                 
                                           ▒
                        alignedAlloc0__system_u1947 (inlined)                   
                                           ▒
                      - allocShared0Impl__system_u1776 (inlined)                
                                           ▒
                         + 8.03% zeroMem__system_u1742 (inlined)                
                                           ▒                     + 2.49% 
allocSharedImpl (inlined)                                                       
          ▒                 7.57% 0x7f0ab6ca3c4a                                
                                                  ▒           1.02% 
rawGet__related_u675 (inlined)                                                  
                      ▒      + 1.75% eqdestroy___related_u249 (inlined)
    
    
    Run

where `X5BX5D___related_u2269` is `[]` which calls the `eqcopy` which allocate 
new seq

Is it something expected? Because I have an assumption that it is possible to 
do it without the copying 

Reply via email to