nickel-lang / json-schema-to-nickel

Convert JSON schemas into Nickel contracts
Apache License 2.0
29 stars 0 forks source link

Some generated schemas are very slow #47

Open thufschmitt opened 8 months ago

thufschmitt commented 8 months ago

I wanted to use a schema generated from https://json.schemastore.org/github-workflow.json in my Nickel configuration. However, just applying this contract to a simple action file takes in the order of one second (which is more than what I can reasonably accept).

To reproduce

$ curl -LO https://github.com/thufschmitt/nickel-schemastore/raw/master/out/GitHub%20Workflow.ncl                   
$ cat <<EOF > github-action.yml                                                                   
name: "CI"                                                                                                          

on:                                                                                                                 
  pull_request:                                                                                                     
  push:                                                                                                             

permissions: read-all                                                                                               

jobs:                                                                                                               

  tests:                                                                                                            
    strategy:                                                                                                       
      fail-fast: false                                                                                              
      matrix:                                                                                                       
        os: [ubuntu-latest, macos-latest]                                                                           
    runs-on: \${{ matrix.os }}                                                                                      
    timeout-minutes: 60                                                                                             
    steps:                                                                                                          
    - uses: actions/checkout@v4                                                                                     
      with:                                                                                                         
        fetch-depth: 0          
EOF
$ time nickel export <<<'let gh = import "GitHub%20Workflow.ncl" in (import "github-action.yml") | gh'
...
nickel export <<<   1,05s user 0,05s system 99% cpu 1,104 total

Notes

The check-jsonschema tool is not tremendously faster (takes around 0.88s for the same file), so maybe it's just the inherent complexity of the schema. But I suspect this could be made faster