How is spdlog so fast ?? #2370
Replies: 4 comments 2 replies
-
Without measuring benchmarks, it is difficult to determine the cause of slow single-thread API, but in general I/O operations tend to be slower. One of spdlog's tricks is to delay I/O flushes. This trick reduces I/O latency and thus improves code performance. |
Beta Was this translation helpful? Give feedback.
-
Can Please tell you more tricks |
Beta Was this translation helpful? Give feedback.
-
There should be more tricks |
Beta Was this translation helpful? Give feedback.
-
There's really no better trick than just measuring and profiling your code - one tip is to mess with/add functionality to increase the file buffer used; while spdlog delays the OS call for flushing, file buffers are still flushed to disk when they are full. Therefore, increasing the size of that buffer for your use case will also speed times up quite a bit. The default size is generally usually 8k so you could use that as a starting point for using setvbuf() for instance. Spdlog's speed in formatting the timestamp portion heavily relies on manual structures hand-rolled to mimic what you would get from a strftime call; there's really nothing faster than a specific hand-rolled version for your use case rather than relying on generic broad functions as a general rule-of-thumb. The more abstracted your function calls are, the more likely there's some overhead that you incur; so the lower you get to OS-specific code you can get, the faster your code will tend to be (not always, but usually). |
Beta Was this translation helpful? Give feedback.
-
I have been trying to make my own logging framework , and I realized that my single threaded api is really slow , how is spdlog so fast (single - threaded).
Beta Was this translation helpful? Give feedback.
All reactions