iacobson / ecspanse

Entity Component System (ECS) library for Elixir, offering a suite of features including: flexible queries with multiple filters, dynamic bidirectional relationships, versatile tagging capabilities, system event subscriptions, or asynchronous system execution.
https://hexdocs.pm/ecspanse
Apache License 2.0
63 stars 7 forks source link

`:ets.new(..., [..., write_concurrency: :auto])` only works with Erlang OTP-26 #28

Closed Bastes closed 7 months ago

Bastes commented 7 months ago

Hello,

Following the tutorial, I've generated a fresh new phoenix v1.7.11 with Ecspanse v0.8.1 on elixir v1.14.0 and with Erlang/OTP v24, and was surprised to get an error right after plugging the Ecspanse app in the application module:

** (Mix) Could not start application ecs: Ecs.Application.start(:normal, []) returned an error: shutdown: failed to start child: Ecs
    ** (EXIT) an exception was raised:
        ** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: invalid options

            (stdlib 3.17.2.4) :ets.new(:ets_ecspanse_components_state, [:set, :public, :named_table, {:read_concurrency, true}, {:write_concurrency, :auto}])
            (ecspanse 0.8.1) lib/ecspanse/server.ex:134: Ecspanse.Server.init/1
            (stdlib 3.17.2.4) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.17.2.4) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.17.2.4) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

This led me to this line:

https://github.com/iacobson/ecspanse/blob/2eb2f0eac9a922b0f574d599c15e9cdd08d2d87d/lib/ecspanse/server.ex#L139

    :ets.new(Util.components_state_ets_table(), [
      :set,
      :public,
      :named_table,
      read_concurrency: true,
      write_concurrency: :auto
    ])

From the :ets otp module, I see the :auto atom for write_concurrency has only been added in Erlang/OTP v26.

I'm going to restart using a later Elixir and Erlang/OTP v26, but I thought you might want to know in case you'd like backwards compatibility or something.

Bastes commented 7 months ago

(and I can now confirm it starts fine with Elixir v1.16.2-otp-26 + Erlang/OTP 26.2.3)

iacobson commented 7 months ago

Hi @Bastes

Thanks for trying the library and especially for investigating this issue. Indeed, when developing Ecspanse I focused on the latest Elixir and Erlang released.

I'm not sure yet how to make it compatible with older OTP versions. Of course, I could replace :auto, but I would not want to trade functionality for backwards compatibility.

For now, I will add a Requirements sections in the docs and clearly state that you need OTP-25 and above to run the library.

If you have any other suggestion, please share it.

Thanks again!

Bastes commented 7 months ago

Yes, I think simply publicising the requirements would be enough :) by the way, I'm almost done playing with the tutorial and it's behaving quite nicely :) thank you for your work.

iacobson commented 7 months ago

Thanks so much 🙏 !