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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SnowflakeUtil): add timestampFrom #7058

Merged
merged 1 commit into from Dec 6, 2021

Conversation

kyranet
Copy link
Member

@kyranet kyranet commented Dec 2, 2021

Please describe the changes this PR makes and why it should be merged:

Also refactors anything using SnowflakeUtil.deconstruct(id).timestamp to use this new utility. This continues the work in #7036.

SnowflakeUtil.timestampFrom is a performance-focused utility designed to skip a lot of the decoder's overhead, as shown in the chart below:

Iterations deconstruct(id).timestamp New timestampFrom Diff
10000 36.08ms 4.29ms 8.41
100000 191.35ms 31.97ms 5.99
1000000 1.83s 264.89ms 6.91

In retrospective, the deconstruct method in main is almost twice as fast as the one in 13.3.1, so we'll see a large performance boost in many createdTimestamp getters across the library in the next version 馃憖

Also, something odd I noticed is that we don't read data.timestamp in Message, as the value it yields is identical to getting the timestamp field from the ID, perhaps we can remove the field and reduce memory usage for messages, as well as lazy calculate the value? Perhaps it was stored due to performance concerns since sweepers rely on createdTimestamp, but with this performance boost, it should be reasonably fast for the performance trade-off (?)

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)

@iCrawl iCrawl merged commit 8b200c0 into discordjs:main Dec 6, 2021
@kyranet kyranet deleted the feat/snowflake-util-timestamp-from branch January 7, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants