-
Notifications
You must be signed in to change notification settings - Fork 67
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
fix(weave): optimize finding next tick up or down #3231
base: master
Are you sure you want to change the base?
Conversation
Preview this PR with FeatureBee: https://beta.wandb.ai/?betaVersion=147e5b610b5e7647a2300a61ce65496d23143dea |
diff < minDiff && | ||
((increasing && tick >= val) || (!increasing && tick <= val)) | ||
) { | ||
closest = tick; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have something to break out early if tick is equal to val?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, lets not go searching through half the list if the slider increments to a valid step, heh. Good call.
const end = Date.now(); | ||
const duration = end - start; | ||
expect(actual).toBe(500002); | ||
expect(duration).toBeLessThanOrEqual(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests are awesome! could you add one for testing the bounds as well? like one where the val is less than the smallest tick and also one where the val is larger than the largest tick?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I like it, sure. That logic lives in the update()
function that calls getClosestTick()
when it has a list of ticks. I might suck that logic into this function instead, and leave update()
as a, "get the right value and synchronize the inputs fields."
Description
Fixes
getNearestTick()
inSliderInput.tsx
by including the existing value of the slider to to determine whether to look above or below the previous value.Optimized function for better performance over large lists.
Included a new test file for basic unit tests of the function.
Testing
Added new unit tests to verify basic functionality.
Created a project with varying steps to ensure slider increments appropriately.