-
Notifications
You must be signed in to change notification settings - Fork 5
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
Reduce compiler complexity with ScryfallCards.Any #20
Comments
Just some of my 2 cents for this project, this is also related to #10. I think you may want to consider how much type level encoding you want to have. Currently this project seems to be aiming to create an API with as narrow types as possible, describing as closely as possible the actual set of scryfall API responses within the type system. That's fine, but it comes with some tradeoffs that you are choosing to make. As a point of example consider /** A card with the Planar layout. */
export type Planar = Layout<ScryfallLayout.Planar> & SingleFace & AlwaysOversized;
/** A card with the Scheme layout. */
export type Scheme = Layout<ScryfallLayout.Scheme> & SingleFace & AlwaysOversized; We have the planar and scheme cards having their For another example, consider the types in export type Integer = number;
export type Decimal = number;
export type Uuid = string;
export type Uri = string;
export type IsoDate = string; Writing type aliases may help the user understand that a string in a type actually represents a uuid, or is formatted like a date. However, it is also an extra layer of indirection the user must incur every time they encounter one of those types. Hmm, this object has a field of type As a counterpoint, I'm currently using scryfall-types in a project that uses the scryfall API. Although the types are a lot more coarse than this library, it provided adequate enough type checking for me to consume the scryfall API, which is all that I care about. As a plus, grokking the types offered by the API was a lot more straightforward since most types were mostly flat. For example the My opinion of the current state of the project is that too much information is being encoded at the type level. Yes, some of it does provide narrowing type information for the user in some cases, but it also increases the overall complexity of the project for both the compiler and users. |
@thesilican Thank you. That's genuinely helpful feedback and insight. I've had a plan to revise the card system and essentially pull out some of the too-specific guts and I'm going to use that to inform making it much simpler overall. |
While dogfooding on this library with other projects to test the current alpha candidate, I've determined that the
ScryfallCard.Any
type is a severe performance problem for the compiler.The current API-types library is built around modular joins because that lends itself to describing the Scryfall API effectively.
Each layout involves twenty-or-more joins, and
ScryfallCard.Any
is a range of 23 of those. That multiplies out to more than 400 joins. The TS compiler can find working with that to be quite slow. Once that gets added into a system with any additional layers of computational complexity, that can balloon out to thousands or tens of thousands of layers of complexity, and the TS compiler can outright give up.ScryfallCard definitions need to be replaced so that we no longer refer to cards on a per-layout basis, but instead merge functionally identical definitions together. We can of course also export per-layout types, but they can be derived from that type instead.
The text was updated successfully, but these errors were encountered: