Re: [vim/vim] fix: ":for" over a tuple leaks memory on every iteration (PR #20914)
Samuel Schlesinger (Vim Github Repository) <[email protected]> Sun, 02 Aug 2026 04:32:38 -0700
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/20914/[email protected]> |
----==_mimepart_6a6f2ad665b23_cc1160721964b
Content-Type: text/plain; charset="UTF-8"
SamuelSchlesinger left a comment (vim/vim#20914)
Here's one you can verify from outside of the code, it is a bit more minimal:
```vimscript
" Minimal reproduction of the ":for" over a tuple memory leak.
" The script uses nothing but :let, :while and :for. Measure memory from
" the outside:
"
" macOS: /usr/bin/time -l ./vim -N -u NONE -i NONE -es -S tuple_leak_demo.vim
" Linux: /usr/bin/time -v ./vim -N -u NONE -i NONE -es -S tuple_leak_demo.vim
"
" Observed max RSS (macOS, 1,000,000 iterations):
" unpatched: 93.0 MB (~80 bytes leaked per iteration: the copied items)
" patched: 12.8 MB
"
" Control: change the tuple (...) below into a list [...] and the unpatched
" max RSS drops to 12.7 MB, isolating the leak to the tuple code path.
let i = 0
while i < 1000000
for x in ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'b')
endfor
let i += 1
endwhile
qa!
```
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20914#issuecomment-5157544718
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/20914/[email protected]>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/20914/c5157544718%40github.com.
----==_mimepart_6a6f2ad665b23_cc1160721964b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div style=3D"display: flex; flex-wrap: wrap; white-space: pre-wrap; align-=
items: center; "><img height=3D"20" width=3D"20" style=3D"border-radius:50%=
; margin-right: 4px;" decoding=3D"async" src=3D"https://avatars.githubuserc=
ontent.com/u/10200200" /><strong>SamuelSchlesinger</strong> left a comment =
<a href=3D"https://github.com/vim/vim/pull/20914#issuecomment-5157544718">(=
vim/vim#20914)</a></div>
<p dir=3D"auto">Here's one you can verify from outside of the code, it is a=
bit more minimal:</p>
<div class=3D"highlight highlight-source-viml" dir=3D"auto"><pre class=3D"n=
otranslate"><span class=3D"pl-c"><span class=3D"pl-c">"</span> Minimal repr=
oduction of the ":for" over a tuple memory leak.</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> The script uses nothing =
but :let, :while and :for. Measure memory from</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> the outside:</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span></span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> macOS: /usr/bin/time =
-l ./vim -N -u NONE -i NONE -es -S tuple_leak_demo.vim</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span><span class=3D"pl-c1"> =
Linux:</span> /usr/bin/time -v ./vim -N -u NONE -i NONE -es -S tuple_leak_=
demo.vim</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span></span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> Observed max RSS (macOS,=
1,000,000 iterations):</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> unpatched: 93.0 MB =
(~80 bytes leaked per iteration: the copied items)</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> patched: 12.8 MB</s=
pan>
<span class=3D"pl-c"><span class=3D"pl-c">"</span></span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span><span class=3D"pl-c1"> Co=
ntrol:</span> change the tuple (...) below into a list [...] and the unpatc=
hed</span>
<span class=3D"pl-c"><span class=3D"pl-c">"</span> max RSS drops to 12.7 MB=
, isolating the leak to the tuple code path.</span>
<span class=3D"pl-k">let</span> <span class=3D"pl-c1">i</span> <span class=
=3D"pl-k">=3D</span> <span class=3D"pl-c1">0</span>
<span class=3D"pl-k">while</span> <span class=3D"pl-c1">i</span><span class=
=3D"pl-k"> < </span><span class=3D"pl-c1">1000000</span>
<span class=3D"pl-k">for</span> <span class=3D"pl-c1">x</span> <span clas=
s=3D"pl-k">in</span> (<span class=3D"pl-s"><span class=3D"pl-pds">'</span>a=
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<span class=3D"pl-pds">'</=
span></span>, <span class=3D"pl-s"><span class=3D"pl-pds">'</span>b<span cl=
ass=3D"pl-pds">'</span></span>)
<span class=3D"pl-k">endfor</span>
<span class=3D"pl-k">let</span> <span class=3D"pl-c1">i</span> <span clas=
s=3D"pl-k">+=3D</span> <span class=3D"pl-c1">1</span>
<span class=3D"pl-k">endwhile</span>
<span class=3D"pl-c1">qa</span><span class=3D"pl-k">!</span></pre></div>
<p style=3D"font-size:small;-webkit-text-size-adjust:none;color:#666;">&mda=
sh;<br />Reply to this email directly, <a href=3D"https://github.com/vim/vi=
m/pull/20914#issuecomment-5157544718">view it on GitHub</a>, or <a href=3D"=
https://github.com/notifications/unsubscribe-auth/ACY5DGG2CQYQUGL6POMWX2L5H=
4RFNAVCNFSNUABEKJSXA33TNF2G64TZHM2DAOJZG42DQMR3JFZXG5LFHM2TAMZYG4YDANRVGSQX=
MAQ">unsubscribe</a>.<br />Triage notifications, keep track of coding agent=
tasks and review pull requests on the go with GitHub Mobile for <a href=3D=
"https://github.com/notifications/mobile/ios/ACY5DGHEC5ISKNM5YYNDGW35H4RFNA=
5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJVG42TINBXGE4KM4TFM=
FZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ">iOS</a> and <a href=3D=
"https://github.com/notifications/mobile/android/ACY5DGHDCJQZSUULSZYVWLD5H4=
RFNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJVG42TINBXGE4KM=
4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ">Android</a>.=
Download it today!
<br />You are receiving this because you are subscribed to this thread.<img=
src=3D"https://github.com/notifications/beacon/ACY5DGHA3MUJ7QREJIFS3V35H4R=
FNBFCNFSM6AAAAAC4V66BCKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3=
TUL5UWJTYAAAAACM3J4MHKM4TFMFZW63VKON2WE43DOJUWEZLE.gif" height=3D"1" width=
=3D"1" alt=3D"" /><span style=3D"color: transparent; font-size: 0; display:=
none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: =
0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><vim/vi=
m/pull/20914/c5157544718</span><span>@</span><span>github</span><span>.</sp=
an><span>com></span></span></p>
<script type=3D"application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/vim/vim/pull/20914#issuecomment-5157544718",
"url": "https://github.com/vim/vim/pull/20914#issuecomment-5157544718",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>
<p></p>
-- <br />
-- <br />
You received this message from the "vim_dev" maillist.<br />
Do not top-post! Type your reply below the text you are replying to.<br />
For more information, visit <a href=3D"http://www.vim.org/maillist.php">htt=
p://www.vim.org/maillist.php</a><br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;vim_dev" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">vim_dev+uns=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
vim_dev/vim/vim/pull/20914/c5157544718%40github.com?utm_medium=3Demail&utm_=
source=3Dfooter">https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/209=
14/c5157544718%40github.com</a>.<br />
----==_mimepart_6a6f2ad665b23_cc1160721964b--