From 39694a29497aee87d6ee91155e9b7570b7849aa9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:56:07 +0200 Subject: [PATCH] Add speedups.rst --- docs/source/index.rst | 2 +- docs/source/topics/speedups.rst | 65 +++++++++++++++++++++++++++++++++ docs/source/topics/tgcrypto.rst | 29 --------------- pyrogram/crypto/aes.py | 2 +- 4 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 docs/source/topics/speedups.rst delete mode 100644 docs/source/topics/tgcrypto.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 5ee12b7e..885f79dd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -143,7 +143,7 @@ Meta topics/client-settings topics/synchronous topics/text-formatting - topics/tgcrypto + topics/speedups topics/smart-plugins topics/storage-engines topics/serializing diff --git a/docs/source/topics/speedups.rst b/docs/source/topics/speedups.rst new file mode 100644 index 00000000..6340e1ad --- /dev/null +++ b/docs/source/topics/speedups.rst @@ -0,0 +1,65 @@ +Speedups +======== + +Pyrogram's speed can be boosted up by using TgCrypto and uvloop. + +.. contents:: Contents + :backlinks: none + :depth: 1 + :local: + +----- + +TgCrypto +-------- + +TgCrypto_ is a high-performance, easy-to-install cryptography library specifically written in C for Pyrogram as a Python +extension. It is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram +requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC. + +Installation +^^^^^^^^^^^^ + +.. code-block:: bash + + $ pip3 install -U tgcrypto + +Usage +^^^^^ + +Pyrogram will automatically make use of TgCrypto when detected, all you need to do is to install it. + +uvloop +------ + +uvloop_ is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses +libuv under the hood. It makes asyncio 2-4x faster. + +Installation +^^^^^^^^^^^^ + +.. code-block:: bash + + $ pip3 install -U uvloop + +Usage +^^^^^ + +Call ``uvloop.install()`` before calling ``asyncio.run()`` or ``app.run()`` + +.. code-block:: python + + import asyncio + import uvloop + + async def main(): + app = Client("my_account") + + async with app: + print(await app.get_me()) + + uvloop.install() + asyncio.run(main()) + +.. _TgCrypto: https://github.com/pyrogram/tgcrypto +.. _uvloop: https://github.com/MagicStack/uvloop diff --git a/docs/source/topics/tgcrypto.rst b/docs/source/topics/tgcrypto.rst deleted file mode 100644 index f6ca211d..00000000 --- a/docs/source/topics/tgcrypto.rst +++ /dev/null @@ -1,29 +0,0 @@ -Fast Crypto -=========== - -Pyrogram's speed can be boosted up by TgCrypto_, a high-performance, easy-to-install cryptography library specifically -written in C for Pyrogram as a Python extension. - -TgCrypto is a replacement for a slower Python-only alternative and implements the cryptographic algorithms Telegram -requires, namely: AES-256-IGE, AES-256-CTR and AES-256-CBC. - -Installation ------------- - -.. code-block:: bash - - $ pip3 install -U tgcrypto - -.. note:: When TgCrypto is not detected in your system, Pyrogram will automatically fall back to a slower Python-only - implementation and will show you a warning. - -The reason about being an optional package is that TgCrypto requires extra system tools in order to be compiled. -The errors you receive when trying to install TgCrypto are system dependent, but also descriptive enough to understand -what you should do next: - -- **Windows**: Install `Visual C++ 2015 Build Tools `_. -- **macOS**: A pop-up will automatically ask you to install the command line developer tools. -- **Linux**: Install a proper C compiler (``gcc``, ``clang``) and the Python header files (``python3-dev``). -- **Termux**: Install ``clang`` package. - -.. _TgCrypto: https://github.com/pyrogram/tgcrypto \ No newline at end of file diff --git a/pyrogram/crypto/aes.py b/pyrogram/crypto/aes.py index 532cd5e8..bb937128 100644 --- a/pyrogram/crypto/aes.py +++ b/pyrogram/crypto/aes.py @@ -54,7 +54,7 @@ except ImportError: log.warning( "TgCrypto is missing! " "Pyrogram will work the same, but at a much slower speed. " - "More info: https://docs.pyrogram.org/topics/tgcrypto" + "More info: https://docs.pyrogram.org/topics/speedups" )