Cache properties before emmiting a signal on document reset
This method:
- Checks property changes before emitting signals, reducing signal emissions when properties are unchanged.
- Slightly slower per call due to property getter overhead (e.g., creating a copy of QTextCursor for fontFamily(), bold(), etc.).
- Likely faster overall since QML slots are expensive, as it minimizes unnecessary UI updates.
For a benchmark, let's try to minimize calls with Qt.callLater(func):
Use this function to eliminate redundant calls to a function or signal.
Qt.callLater(() => handler.benchmarkResetMethods(1000));
Benchmarks
Run #1
Starting benchmark for 1000 iterations...
"resetOriginal" took 2018 ms for 1000 iterations
"resetOptimized" took 36 ms for 1000 iterations
Benchmark complete.
Run #2
Starting benchmark for 1000 iterations...
"resetOriginal" took 2021 ms for 1000 iterations
"resetOptimized" took 39 ms for 1000 iterations
Benchmark complete.
Run #3
Starting benchmark for 1000 iterations...
"resetOriginal" took 2042 ms for 1000 iterations
"resetOptimized" took 38 ms for 1000 iterations
Benchmark complete.
-
resetOriginalis the original impl. -
resetOptimizedis the commit impl.
Notes
- 1000 iterations simulate frequent calls (e.g., ~3–5 minutes of typing at 60 WPM).
- Use
QElapsedTimeras it provides high-resolution timing, ensuring accurate measurements. -
QTimerwith a 0 ms interval runs as fast as the event loop allows, but there’s minimal overhead per iteration. - This MR also fixes a wrong signal usage (see second commit).