Split validation via dry-rb into seperate gem
pfeiffer opened this issue · comments
Hi!
Since version 2.1 config
supports validation via dry-rb
. Unfortunately this dependency results in a quite high memory usage.
Output using derailed bundle:mem
:
rails/all: 25.1523 MiB
rails: 9.4883 MiB
...
config: 7.1172 MiB
config/validation/schema: 6.6563 MiB (Also required by: config/validation/schema)
dry-schema: 6.6367 MiB
dry/schema: 6.6211 MiB
dry/schema/dsl: 6.5039 MiB
dry/schema/config: 4.3203 MiB (Also required by: dry/schema/rule_applier)
dry/schema/type_container: 3.8398 MiB (Also required by: dry/schema/processor)
dry/types: 3.4727 MiB (Also required by: dry/schema/types)
dry/types/nominal: 1.8398 MiB
dry/types/builder: 1.0703 MiB
dry/types/constrained: 0.707 MiB
dry/types/constraints: 0.6523 MiB
dry/logic/rule_compiler: 0.5977 MiB (Also required by: dry/schema/compiler)
dry/logic/rule: 0.5234 MiB (Also required by: dry/logic/rule/predicate)
dry/logic/operations: 0.4023 MiB
dry/types/array: 0.3008 MiB
dry/types/core: 0.6758 MiB
dry/types/inflector: 0.3984 MiB
dry/inflector: 0.3242 MiB
dry/container: 0.3555 MiB (Also required by: dry-container, dry/types/container)
dry/schema/macros: 1.0977 MiB
dry/schema/macros/optional: 0.6094 MiB
dry/schema/macros/key: 0.582 MiB (Also required by: dry/schema/macros/required)
dry/schema/processor: 0.4922 MiB (Also required by: dry/schema/dsl, dry/schema/params)
dry/schema/rule_applier: 0.4531 MiB (Also required by: dry/schema/dsl)
dry/schema/message_compiler: 0.3125 MiB
In our app with quite a lot of dependencies, this makes config
the second most memory hungry gem after rails
.
Would it be an idea to split the validation feature into a separate optional gem, that could be included if this functionality is wanted? This would cut down significantly on the memory impact of including the core config
gem making inclusion of dry-rb
optional for the developer.
I digged a little in the code and found #253 that defers requiring dry-validation
until a schema is defined. After upgrading the gem to latest version, I no longer see config
using as much memory as mentioned above.
Closing this issue for now :-)
I am glad we had you covered ;)
@pkuczynski actually...
I'll maybe open a PR here with more information, but if you could tell me your interest in my next proposition I'd be glad.
Depending on dry-validation
doesn't just bring runtime issues (which are covered, as discussed in this conversation). It also bring:
- a larger stack, hence longer
bundle install
and necessity for more ROM in production (which can matter, for instance Heroku instances ask for a quite small app size ) - a gemfile lock dependency, forcing version of dry-* gems. Some may want to still be in 0.X, or when dry 2.X goes out, some may want to jump into that, and if they are not using the schema feature for config, it is sad to block those people.
Hence my design intention is:
- replace the dependency with a dev-dependency,
- check at runtime if the dependency is met, and if is matches dev-dependency expected version,
- add related tests :)
Here's a fork we're using at Stuart in the meantime: https://github.com/StuartApp/config
Would you like that ?