docs: update descriptions about improve I/O performance

This commit is contained in:
Linda
2024-09-06 18:25:02 +08:00
committed by BOT
parent fe47676a8b
commit ef1bffa937
2 changed files with 19 additions and 10 deletions

View File

@@ -299,15 +299,20 @@ Improving Network Speed
Improving I/O Performance
-------------------------
Using standard C library functions like ``fread`` and ``fwrite`` instead of platform specific unbuffered syscalls such as ``read`` and ``write`` can be slow.These functions are designed to be portable, so they are not necessarily optimized for speed, have a certain overhead and are buffered.
Using standard C library functions like ``fread`` and ``fwrite`` instead of platform-specific unbuffered syscalls such as ``read`` and ``write``, may result in slower performance.
:doc:`/api-reference/storage/fatfs` specific information and tips:
The ``fread`` and ``fwrite`` functions are designed for portability rather than speed, introducing some overhead due to their buffered nature. Check the example :example:`storage/fatfsgen` to see how to use these two functions.
In contrast, the ``read`` and ``write`` functions are standard POSIX APIs that can be used directly when working with FatFs through VFS, with ESP-IDF handling the underlying implementation. Check the example :example:`storage/perf_benchmark` to see how to use the two functions.
Additional tips are provided below, and further details can be found in :doc:`/api-reference/storage/fatfs`.
.. list::
- Maximum size of the R/W request = FatFS cluster size (allocation unit size).
- Use ``read`` and ``write`` instead of ``fread`` and ``fwrite``.
- To increase speed of buffered reading functions like ``fread`` and ``fgets``, you can increase a size of the file buffer (Newlib's default is 128 bytes) to a higher number like 4096, 8192 or 16384. This can be done locally via the ``setvbuf`` function used on a certain file pointer or globally applied to all files via modifying :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE`.
- The maximum size of a read/write request is equal to the FatFS cluster size (allocation unit size).
- For better performance, prefer using ``read`` and ``write`` over ``fread`` and ``fwrite``.
- To improve the speed of buffered reading functions like ``fread`` and ``fgets``, consider increasing the file buffer size. The default size in Newlib is 128 bytes, but you can increase it to 4096, 8192, or 16384 bytes. This can be made locally using the ``setvbuf`` function for a specific file pointer or globally by modifying the ``CONFIG_FATFS_VFS_FSTAT_BLKSIZE`` setting.
.. note::
Setting a bigger buffer size also increases the heap memory usage.
Increasing the buffer size will also increase heap memory usage.

View File

@@ -299,15 +299,19 @@ ESP-IDF 支持动态 :doc:`/api-reference/system/intr_alloc` 和中断抢占。
提高 I/O 性能
----------------------------------
使用标准 C 库函数,如 ``fread````fwrite``,相较于使用平台特定的不带缓冲系统调用,I/O 性能可能更慢,``read````write`` 。标准 C 库函数是为可移植性而设计的,它们会在执行时会引入一定开销和缓冲延迟,因此并不适用需要较高执行速度的场景。
使用标准 C 库函数,如 ``fread````fwrite``,相较于使用平台特定的不带缓冲系统调用,如 ``read````write``,可能会导致 I/O 性能下降。
:doc:`/api-reference/storage/fatfs` 具体信息和提示如下:
``fread````fwrite`` 函数是为可移植性而设计的,而非速度,其缓冲性质会引入一些额外的开销。关于如何使用这两个函数,请参考示例 :example:`storage/fatfsgen`
与之相比,``read````write`` 函数是标准的 POSIX API可直接通过 VFS 处理 FatFs由 ESP-IDF 负责底层实现。关于如何使用这两个函数,请参考示例 :example:`storage/perf_benchmark`
下面提供了一些提示,更多信息请见 :doc:`/api-reference/storage/fatfs`
.. list::
- 读取/写入请求的最大大小等于 FatFS 簇大小(分配单元大小)。
- 使用 ``read````write`` 而非 ``fread````fwrite`` 可以提高性能。
- 要提高诸如 ``fread````fgets`` 等缓冲读取函数的执行速度,可以增加文件缓冲区的大小Newlib 的默认值为 128 字节),例如 4096、8192 或 16384 字节。为此,可以在特定文件的指针上使用 ``setvbuf`` 函数进行局部更改,或者修改 :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE` 实现全局应用
- 为了获得更好的性能,建议使用 ``read````write``而非 ``fread````fwrite``
- 要提高诸如 ``fread````fgets`` 等缓冲读取函数的执行速度,可以增加文件缓冲区的大小Newlib 的默认值为 128 字节,但可将其增加到 4096、8192 或 16384 字节。为此,可以使用 ``setvbuf`` 函数对特定文件指针进行局部设置,或者通过修改 :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE` 设置来进行全局修改
.. note::
增加缓冲区的大小会增加堆内存的使用量。