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

MOB462 Expose marginUsage from isolated positions #322

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

johnqh
Copy link
Contributor

@johnqh johnqh commented Apr 29, 2024

Simple PR: Design shows the margin usage changes for the isolated position. That needs to be exposed in object.

Copy link

linear bot commented Apr 29, 2024

@@ -400,6 +406,7 @@ data class SubaccountPosition(
existing.resources !== resources ||
existing.childSubaccountNumber !== childSubaccountNumber ||
existing.freeCollateral !== freeCollateral ||
existing.marginUsage !== marginUsage ||
Copy link
Contributor

@prashanDYDX prashanDYDX Apr 29, 2024

Choose a reason for hiding this comment

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

Why are we using referential equality here?

Also taking a step back, what is the goal of this if block? Why does returning existing vs a new object matter? Do we need to check fields one by one? Why not just construct the object and use built-in data class equality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, childSubaccountNumber is not an object so shouldn't be referential equality. Changed.

All others are objects.

Those output objects can be larger hierarchal objects. Creating data object from IMap will be slower since it is not just a single object being created. It is important for abacus to be as fast as possible as we are dealing with three platforms.

When existing object (which enables referential equality) is returned, downstream code uses referential equality to check if additional code gets triggered. Again, this gives us much better performance than returning a data object even if there is no change.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see, i'm curious if this architecture was adopted in response to actual perf problems or if it's more theoretical? it is not a common pattern and sort of fragile with new devs onboarding, i could easily see someone accidentally creating new objects instead of checking against existing.

Copy link
Contributor

@prashanDYDX prashanDYDX left a comment

Choose a reason for hiding this comment

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

approving for now to unblock, but do think this is worth discussing more

@johnqh johnqh merged commit 8af0b17 into main Apr 30, 2024
3 checks passed
@johnqh johnqh deleted the features/MOB-462-surface-margin-usage branch April 30, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants