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

experimental_customMergeAllOf #4308

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MarekBodingerBA
Copy link
Contributor

@MarekBodingerBA MarekBodingerBA commented Sep 20, 2024

Reasons for making this change

NOTE: This is just a draft PR; details are subject to discussion.

In many cases, json-schema-merge-allof is a performance bottleneck for this library:

getDefaultFormState_original x 141 ops/sec ±2.65% (80 runs sampled)
getDefaultFormState_fastMergeAllOf x 987 ops/sec ±2.72% (77 runs sampled)

I have a couple of questions:

  • Is this something that would be desirable to implement for others?
  • I would like feedback on the naming and types of experimental_customMergeAllOf. Maybe it's better to provide the function wrapped in an object rather than the function itself.
  • schemaParser (which is only used in compileSchemaValidatorsCode) relies internally on retrieveSchemaInternal. I chose not to add this option here; is it necessary to include it?

The functional change is located here, other changes are just adding the argument where needed.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@MarekBodingerBA
Copy link
Contributor Author

MarekBodingerBA commented Sep 20, 2024

When I think about it now, I would probably implement it as an object (that would be easier for future compatibility). I imagine something like this:

export type Experimental_MergeAllOfOptions<S extends StrictRJSFSchema = RJSFSchema> =
  | {
      merger: "default";
      overideOptions: Options; // json-schema-merge-allof options
    }
  | {
      merger: "custom";
      mergeFn: (schema: S) => S;
    }
  | {
      merger: "xyz"; // other library if added in the future
    };

WDYT?

@heath-freenome
Copy link
Member

@MarekBodinger I totally understand why you want to add this. We feel like exposing the Options for json-schema-merge-allof is a bad idea. Honestly, if allof-merge has better performance and doesn't break our exists tests, then we welcome a PR to swap it in. That said, making it an object just to provide a function seems like overkill. So making it be a merge function like you started is fine. Not sure whether we can/want to expose this in the playground.

@nickgros
Copy link
Contributor

Also linking this bug: #2927 which may be fixed by an alternative/improved merge implementation

@nickgros
Copy link
Contributor

I tried to just plug in allof-merge and the only meaningful test failure was this one in retrieveSchemaTest. It looks like allof-merge has a lot of customization options, so it may be worth spending a bit of time to see if the behavior can be tweaked to get it to work properly, and we could make it the default implementation (if you're interested in looking into it @MarekBodingerBA)

@MarekBodingerBA MarekBodingerBA changed the title experimental_customMergeAllOf draft experimental_customMergeAllOf Sep 23, 2024
@MarekBodingerBA MarekBodingerBA marked this pull request as ready for review September 23, 2024 19:32
@MarekBodingerBA
Copy link
Contributor Author

MarekBodingerBA commented Sep 23, 2024

I don't think it is a good to replace json-schema-merge-allof with allof-merge without thorough testing. As a user of this library, I would be concerned about such a change.

The approach already in progress, which introduces an experimental_customMergeAllOf option, is more appropriate. This would allow interested users who understand the implications to provide their own custom implementation, where they could easily incorporate allof-merge if desired.

I've completed the work on this and appreciate the feedback received.

Copy link
Contributor

@nickgros nickgros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nickgros
Copy link
Contributor

@MarekBodingerBA can you resolve the conflicts? Likely because we merged #4312

@MarekBodingerBA
Copy link
Contributor Author

@nickgros Unfortunately, I don't have access to a computer for next three weeks. Is it something that you are able to do, or should we wait until I come back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants