Files
Jungfraujoch/viewer/image_viewer/JFJochSimpleImage.h
T
leonarski_fandClaude Opus 5 501ce1ba3d Viewer: rate-limit hover feedback to ~15 Hz
The status bar, the resolution readout and the magnifier were all regenerated
on every single mouse motion event. Each regeneration repaints, and on a remote
X session a repaint uploads the whole window regardless of how little changed,
so the pointer merely crossing the image saturates the link: measured with a
counting relay in front of the X server, 50 motions over the image cost 273 MB,
and a build with the hover work removed cost 18 KB.

Rate-limit it. Two details matter:

- The limit is applied inline, not from a timer. Running the update inside the
  mouse event keeps its damage in the same repaint as anything else that event
  triggers (a pan). A first attempt deferred the work to a timer instead, which
  split one repaint into two and made panning measurably worse.
- The catch-up that reports the final position is debounced, not queued per
  skipped motion, so it fires once after the pointer stops rather than
  repeatedly mid-gesture.

mouseHover() now takes the scene position and modifiers instead of the event,
which also removes the identical mapToScene() from all four implementations.

Hover traffic over 3 repeats: 173 MB mean -> 140 MB, and the run-to-run spread
drops from +-14% to +-2%. The harness tops out near 30 motions/s, barely above
the 15 Hz limit; a real mouse reports far faster, where the cap does more.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 20:12:36 +02:00

34 lines
848 B
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "JFJochImage.h"
#include <QVector>
#include <QColor>
#include <QPointF>
#include <QRect>
#include <QGraphicsTextItem>
#include <vector>
#include <QTimer>
#include "../SimpleImage.h"
#include "../../common/ColorScale.h"
class JFJochSimpleImage : public JFJochImage {
Q_OBJECT
std::shared_ptr<const SimpleImage> image_;
// Prepare image
template<class T>
void loadImageInternal(const uint8_t *input);
void loadImageInternal();
void mouseHover(const QPointF &scenePos, Qt::KeyboardModifiers modifiers) override;
public:
explicit JFJochSimpleImage(QWidget *parent = nullptr);
public slots:
void setImage(std::shared_ptr<const SimpleImage> img);
};