great work @ben.sless! need to read the code & think about this a bit. could you check the corresponding features from JSON Schema (https://json-schema.org/understanding-json-schema/reference/object.html#dependencies) so that Malli can be as compliant as itβs reasonable with it. I think your suggestion already a superset of what is in JSON Schemaβ¦
meanwhile, a quick poke on the schema inferring / providing: β’ part1: make it suck less (5x faster on sample dataset): https://github.com/metosin/malli/pull/439 β’ part2: make inferring first class, most likely 100x faster: https://github.com/metosin/malli/pull/440
with part2, all schemas are reponsible for describing how values can/not be described with schemas. This will open up things like inferring types from enums etc, e.g. [:enum "small" "medium" "large"]
has a child schema of :string
.
the part1 (5x faster) of new provider is now 68 loc, instead of the old 69. The old was kinda bloated anyways π
β malli git:(faster-inferrer-part1) β cloc src --by-file
15 text files.
15 unique files.
0 files ignored.
<http://github.com/AlDanial/cloc|github.com/AlDanial/cloc> v 1.86 T=0.03 s (571.3 files/s, 180498.1 lines/s)
----------------------------------------------------------------------------------------
File blank comment code
----------------------------------------------------------------------------------------
src/malli/core.cljc 146 46 1779
src/malli/impl/regex.cljc 93 23 508
src/malli/util.cljc 44 15 350
src/malli/transform.cljc 64 22 335
src/malli/generator.cljc 48 13 281
src/malli/error.cljc 24 6 249
src/malli/clj_kondo.cljc 21 3 141
src/malli/json_schema.cljc 23 3 128
src/malli/dot.cljc 7 3 69
src/malli/provider.cljc 10 3 68
src/malli/registry.cljc 15 3 65
src/malli/swagger.cljc 14 4 51
src/malli/impl/util.cljc 7 0 24
src/malli/edn.cljc 3 0 16
src/malli/sci.cljc 1 0 11
----------------------------------------------------------------------------------------
SUM: 520 144 4075
----------------------------------------------------------------------------------------
β malli git:(faster-inferrer-part1) cloc test --by-file
11 text files.
11 unique files.
0 files ignored.
<http://github.com/AlDanial/cloc|github.com/AlDanial/cloc> v 1.86 T=0.04 s (264.8 files/s, 133395.9 lines/s)
-----------------------------------------------------------------------------------
File blank comment code
-----------------------------------------------------------------------------------
test/malli/core_test.cljc 330 6 1902
test/malli/util_test.cljc 115 4 789
test/malli/transform_test.cljc 93 3 714
test/malli/error_test.cljc 42 3 439
test/malli/generator_test.cljc 39 3 266
test/malli/swagger_test.cljc 11 4 258
test/malli/json_schema_test.cljc 14 4 236
test/malli/dot_test.cljc 12 0 73
test/malli/registry_test.cljc 10 2 61
test/malli/clj_kondo_test.cljc 8 0 55
test/malli/provider_test.cljc 4 0 41
-----------------------------------------------------------------------------------
SUM: 678 29 4834
-----------------------------------------------------------------------------------
Regarding part 1, from the profiling I did yesterday it looks like most CPU is based on miu/-fail
. I'll profile again with part1 merged to see what conclusions I can infer
disregard the last message I had some repl state
ok, see ~2x speedup
-fail
still dominates CPU, though.
Would you like me to prepare a MR for the exception speedup?
Question about Malli's design - what's the rationale behind IntoSchema
s? Why aren't Schema
s and local bindings sufficient?
> For internal elegance, Malli is built using protocols.
>
It,s much easier to program and reason about the system with protocols than against functions / data. IntoSchema
is analogous to a Class
and Schena
to an Object.
There is one shared instance of :map IntoSchema
(in a registry) which describes how to create :map Schema
instances. And soon how to infer schemas from values. Kinda like adding static methods on classes, except it's all polymorphic.