The source of poor performance is that collection items defined as dynamic objects in the MSHTML interop assembly.
public interface IHTMLElementCollection : IEnumerable
{
...
[DispId(0)]
dynamic item(object name = Type.Missing, object index = Type.Missing);
...
}
If we rewrite that interface so it returns IDispatch objects then the lag will disappear.
public interface IHTMLElementCollection : IEnumerable
{
...
[DispId(0)]
[return: MarshalAs(UnmanagedType.IDispatch)]
object item(object name = Type.Missing, object index = Type.Missing);
...
}
New output:
Items: 246, Time: 00:00:00.0034520
Items: 246, Time: 00:00:00.0029398
Items: 246, Time: 00:00:00.0029968