I have made a patch, but we will rewrite that part soon.
You can check the latest trunk with the "knuth" plain format :

%% luaknuthplain.tex
\input plain
\dump


$>luatex -ini  -jobname=luaknuthplain -progname=luaknuthplain luaknuthplain

$>luatex --output-format=pdf --fmt=luaknuthplain.fmt  test.tex 


As test.text I have used 100k iterations (not 10k as in your example), i.e.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\directlua{
  local i = 1
  while i < 100000 do
     local pages = img.scan{filename='foo.pdf'}.pages
     print('Run:', i, 'pages:', pages)
     i = i + 1
  end
}
\bye

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Memory consumption seems also ok ( well enough ok) .

--
luigi