Re: ETS retrieve all objects before deleting the table

Jesper Louis Andersen <[email protected]> Fri, 28 Jan 2022 21:34:52 +0100
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAGrdgiUd5ax=AS5iwZafki5PFkYXu+OWjh5xX98Q8f0q3cfkgw@mail.gmail.com>
On Tue, Jan 18, 2022 at 8:46 AM Frank Muller <[email protected]>
wrote:

> Hi Mikael,
>
> I  tried them all before posting here.
>
> From fastest to slowest:
> 1. select/2 (stable numbers)
> 2. match_object/2
> 3. first/1 + next/2
> 4. tab2list
>
>
You also need to consider memory usage. When you copy a potentially large
ETS table into the heap of a process, you risk blowing up if the table is
large. I'd probably safe_fixtable/2 on the table, traverse it with
match_object/3 1000 elems at a time or so, then remove the fix when
$end_of_table is reached. If any kind of disk I/O is involved, you are
likely to be I/O bound on the disk anyway, or your serialization scheme is
what is going to slow you down. But because of the table fix, you should be
able to work on the disk set in a stable manner.

Clearly, there's some consideration w.r.t if the serialization has to "stop
the world" until the table is on disk. Working around that would be my main
concern.