Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an MVP of the OTP ets interface #887

Open
fadushin opened this issue Oct 23, 2023 · 1 comment
Open

Implement an MVP of the OTP ets interface #887

fadushin opened this issue Oct 23, 2023 · 1 comment
Assignees
Labels
enhancement lib:estdlib Erlang Standard library

Comments

@fadushin
Copy link
Collaborator

fadushin commented Oct 23, 2023

There are cases where AtomVM could benefit from ets tables.

This task would involve implementing a “minimal viable product” for ets in AtomVM. In essence, the minimal implementation should support the ets (unordered) set type, with operations for insertion, lookup, and deletion. Support for sharing tables across processes with support for read-concurrency is desirable, but not strictly needed for the MVP.

Implemented functions of ets (with caveats)would include (but may not necessarily be limited to) the following:

  • ets:new/2 with support for the set type, key_pos, named_table, private, public, and protected access, and read_concrrency (opportunistic)
  • ets:member/2
  • ets:insert/2 and ets:insert_new/2
  • ets:lookup/2 and ets:lookup_element/3
  • ets:delete/2 and ets:delete_all_objects/1
  • ets:tab_to_list/1
  • ets:whereis/1

The implementation should be done as a Bif (I think) and should preserve the same behavior as OTP — specifically, terms that are stored in ets tables should be copied from the process heap into implementation-defined storage (e.g., a heap fragment, or even a (compressed?) encoded term.

@fadushin fadushin added enhancement lib:estdlib Erlang Standard library labels Oct 23, 2023
@fadushin fadushin self-assigned this Feb 7, 2024
bettio added a commit that referenced this issue Apr 4, 2024
Added a limited implementation of the OTP ets interface

***
Few opening words, Fred recently passed away and this is the last time I
will merge a PR from him.

It was an honor to work with you on this project, thanks for your precious help
and for taking part to this journey.

Fred, will miss you.
***

This PR implements a small subset of the OTP `ets` interface.

The following `ets` functions are supported:

* `ets:new/2`
* `ets:insert/2`
* `ets:lookup/2`
* `ets:delete/2`

The following parameters to `ets:new/2` are supported:

* `is_named`
* `{keypos, I :: non_neg_integer()}`
* `private` | `protected` | `public` access types

Only the `set` table type is supported.

This limited functionality allows users to define ETS tables and share term
data between processes in a manner that is more efficient than using message
passing with a process.  The likely initial users of this feature will be the
logging subsystem, as well as parts of the (forthcoming) application support,
for storing application environment settings.

This PR provides a partial implementation of issue #887.  Subsequent PRs can add
additional features from this issue.

For information about the OTP `ets` interface, see
https://www.erlang.org/doc/man/ets.  This implementation attempts to be
API-compatible with the OTP implementation.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
@ceedon
Copy link

ceedon commented Apr 25, 2024

I'm unable to get gleam/mist running due to a dependency on ets:lookup_element/3 .
Does anyone intend to push the rest of this work forward?

I fully understand the unfortunate circumstances around it being partially completed, so forgive me for asking.
I'm trying to understand if I need to start learning C to help do so.

pguyot added a commit to pguyot/AtomVM that referenced this issue Apr 25, 2024
Mentioned in atomvm#887, required to port gleam/mist.
Implementation is in C as initially designed by @fadushin, which saves a
little bit memory as we don't need to copy the whole entry.

Signed-off-by: Paul Guyot <pguyot@kallisys.net>
pguyot added a commit to pguyot/AtomVM that referenced this issue Apr 25, 2024
Mentioned in atomvm#887, required to port gleam/mist.
Implementation is in C as initially designed by @fadushin, which saves a
little bit memory as we don't need to copy the whole entry.

Signed-off-by: Paul Guyot <pguyot@kallisys.net>
bettio added a commit that referenced this issue Apr 27, 2024
Implement ets:lookup_element/3

Mentioned in #887, required to port gleam/mist.
Implementation is in C as initially designed by @fadushin, which saves a little
bit memory as we don't need to copy the whole entry.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement lib:estdlib Erlang Standard library
Projects
None yet
Development

No branches or pull requests

2 participants