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

Proposal for Performance Improvements in JDA Using fastutil and fastjson2 #2787

Open
3 tasks done
rafixtv opened this issue Dec 31, 2024 · 2 comments
Open
3 tasks done

Comments

@rafixtv
Copy link

rafixtv commented Dec 31, 2024

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest JDA version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

Dear JDA Maintainers,
As a user and developer working with your library, I’d like to suggest potential optimizations that could significantly improve performance, particularly when handling large datasets like users, server members, and when processing Discord API responses.
Two libraries that could help achieve these improvements are fastutil and fastjson2. Here’s why I believe these should be considered:

1. Improved Data Storage with fastutil

Fastutil offers highly optimized data structures, especially useful for large datasets. Specifically:

  • Long2ObjectOpenHashMap or Object2ObjectOpenHashMap would provide faster access to data like users and server members. These hashmaps have average O(1) time complexity for get(), put(), and remove() operations, which is perfect for large-scale applications.
  • ObjectArrayList can be used for storing dynamic collections like messages, ensuring fast and efficient data retrieval.
    Using these structures could significantly improve performance when handling large numbers of users or server members (e.g., tens of thousands), reducing memory usage and speeding up common operations.

2. Faster JSON Processing with fastjson2

Fastjson2 is a fast and efficient JSON library, known for:

  • Quicker serialization and deserialization than alternatives like Jackson or Gson.
  • Lower memory overhead, which could improve Discord API response handling, particularly with large user or message data.
    By integrating fastjson2, JDA could speed up API data parsing, reduce response times, and improve overall performance.

3. Benefits:

  • Improved performance when dealing with large datasets like users and server members using fastutil’s optimized collections.
  • Faster API response processing with fastjson2, enhancing bot responsiveness.
  • Reduced memory usage, which is crucial for scalability on large Discord servers.

4. Challenges:

  • Integration would require updating dependencies and possible adjustments in the code, but the benefits would outweigh the costs.
  • Some JDA features might need to be adapted to fully leverage these libraries, but both fastutil and fastjson2 are easy to integrate.

Example Use-Case

Long2ObjectOpenHashMap<User> users = new Long2ObjectOpenHashMap<>();
Long2ObjectOpenHashMap<Member> members = new Long2ObjectOpenHashMap<>();
etc...
@PantherPK
Copy link

I agree that this proposal is great and should be accepted. Using fastutil and fastjson2 is a logical step towards JDA optimization. These libraries can significantly improve performance when handling large datasets, such as users or server members, as well as speed up API response processing. The benefits of implementation far outweigh the potential challenges.

@Andre601
Copy link
Contributor

I feel like there first would need to be benchmarking to see how much the benefit would be compared to the current setup.

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

No branches or pull requests

3 participants