Skip to content

Document how to speed up your bot in a seperate optimizing page #247

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

Merged
merged 2 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ Welcome to Nextcore's documentation!
http
gateway
common

events
releasenotes

.. toctree::
:hidden:

releasenotes
optimizing
contributing/getting_started


Quickstart
==========
First, you need to install the library.
Expand Down
82 changes: 82 additions & 0 deletions docs/optimizing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Optimizing
==========
Heres a few tips to make your bot run a tiny bit faster, from most impact to least. The accuracy of the ordering is more of a guess, and depends on your usage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Heres a few tips to make your bot run a tiny bit faster, from most impact to least. The accuracy of the ordering is more of a guess, and depends on your usage.
Here's a few tips to make your bot run a tiny bit faster, from most impact to least. The accuracy of the orderings is more of a guess, and depends on your usage.


.. Adjust the global rate limit
.. ----------------------------
.. TODO: This needs to be properly supported in HTTPClient first imo.

Relative time
-------------
Nextcore uses your computer's time to work with rate limits.

By default this is on, however your clock might not be syncronized.



.. tab:: Ubuntu

You can check if your clock is synchronized by running the following command:

.. code-block:: bash

timedatectl

If it is synchronized, it will show "System clock synchronized: yes" and "NTP service: running"

If the system clock is not synchronized but the ntp service is running you will have to wait a few minutes for it to sync.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If the system clock is not synchronized but the ntp service is running you will have to wait a few minutes for it to sync.
If the system clock is not synchronized but the NTP service is running you will have to wait a few minutes for it to sync.


To enable the ntp service run the following command:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To enable the ntp service run the following command:
To enable the NTP service run the following command:


.. code-block:: bash

sudo timedatectl set-ntp on

This will automatically sync the system clock every once in a while.

.. tab:: Arch

You can check if your clock is synchronized by running the following command:

.. code-block:: bash

timedatectl

If it is synchronized, it will show "System clock synchronized: yes" and "NTP service: running"

If the system clock is not synchronized but the ntp service is running you will have to wait a few minutes for it to sync.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If the system clock is not synchronized but the ntp service is running you will have to wait a few minutes for it to sync.
If the system clock is not synchronized but the NTP service is running you will have to wait a few minutes for it to sync.


To enable the ntp service run the following command:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To enable the ntp service run the following command:
To enable the NTP service run the following command:


.. code-block:: bash

sudo timedatectl set-ntp on

This will automatically sync the system clock every once in a while.

.. tab:: Windows

This can be turned on by going to ``Settings -> Time & language -> Date & time`` and turning on ``Set time automatically``.

Switch to ORJSON
----------------
Nextcore handles quite a bit of JSON encoding and decoding.
By default, nextcore uses the :mod:`json` module, which is quite a bit slower than :mod:`orjson`

You can switch to ORJSON by installing the speed package and setting it as the global aiohttp default

.. tab:: Pip

.. code-block:: bash

pip install "nextcore[speed]"

.. tab:: Poetry

.. code-block:: bash

poetry add "nextcore[speed]"

This will make :mod:`nextcore.gateway` use orjson, if it is installed.

.. TODO: How do we enable it for nextcore.http too?