Skip to content

Commit 048bd1b

Browse files
committed
perf(scroll): reject dropped events earlier
avoid extra hot-path work for scroll events that will pass through - move continuous, phased, diagonal, and zero-delta checks before flag reads and terminal state lookup - update hot-path profiling option parsing and current precision api call
1 parent f94c571 commit 048bd1b

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

probo/Sources/Events/ScrollEventRewriter.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ struct ScrollEventRewriter {
1515
return false
1616
}
1717

18+
let isContinuous = event.getIntegerValueField(.scrollWheelEventIsContinuous) != 0
19+
if isContinuous {
20+
return false
21+
}
22+
23+
let hasPhase =
24+
event.getIntegerValueField(.scrollWheelEventScrollPhase) != 0
25+
|| event.getIntegerValueField(.scrollWheelEventMomentumPhase) != 0
26+
if hasPhase {
27+
return false
28+
}
29+
30+
let deltaAxis1 = Int32(
31+
truncatingIfNeeded: event.getIntegerValueField(.scrollWheelEventDeltaAxis1))
32+
let deltaAxis2 = Int32(
33+
truncatingIfNeeded: event.getIntegerValueField(.scrollWheelEventDeltaAxis2))
34+
if (deltaAxis1 != 0) == (deltaAxis2 != 0) {
35+
return false
36+
}
37+
1838
let originalFlags = event.flags
1939
let decision = ScrollRewriteCore.decidePrecision(
2040
isOptionHeld: originalFlags.contains(.maskAlternate),
@@ -23,14 +43,11 @@ struct ScrollEventRewriter {
2343
configuration.isTerminalOptimizationEnabled && isTerminalFrontmost(),
2444
)
2545
let input = ScrollRewriteInput(
26-
deltaAxis1: Int32(
27-
truncatingIfNeeded: event.getIntegerValueField(.scrollWheelEventDeltaAxis1)),
28-
deltaAxis2: Int32(
29-
truncatingIfNeeded: event.getIntegerValueField(.scrollWheelEventDeltaAxis2)),
46+
deltaAxis1: deltaAxis1,
47+
deltaAxis2: deltaAxis2,
3048
intensity: configuration.intensity,
31-
isContinuous: event.getIntegerValueField(.scrollWheelEventIsContinuous) != 0,
32-
hasPhase: event.getIntegerValueField(.scrollWheelEventScrollPhase) != 0
33-
|| event.getIntegerValueField(.scrollWheelEventMomentumPhase) != 0,
49+
isContinuous: isContinuous,
50+
hasPhase: hasPhase,
3451
isPrecision: decision.isPrecision,
3552
isTrackpadStyleScrollingEnabled: configuration.isTrackpadStyleScrollingEnabled
3653
)

probo/Tools/HotPathProfile/HotPathProfile.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ struct HotPathProfile {
170170

171171
private func parseOptions() throws -> Options {
172172
var options = Options()
173-
var arguments = Array(CommandLine.arguments.dropFirst())
173+
var arguments = CommandLine.arguments.dropFirst()
174174

175-
while !arguments.isEmpty {
176-
let argument = arguments.removeFirst()
175+
while let argument = arguments.popFirst() {
177176
switch argument {
178177
case "--iterations":
179178
options.iterations = try takePositiveInt(&arguments, argument)
@@ -203,19 +202,19 @@ private func parseOptions() throws -> Options {
203202
return options
204203
}
205204

206-
private func takePositiveInt(_ arguments: inout [String], _ name: String) throws -> Int {
205+
private func takePositiveInt(_ arguments: inout ArraySlice<String>, _ name: String) throws -> Int {
207206
let value = try takeNonNegativeInt(&arguments, name)
208207
if value <= 0 {
209208
throw ProbeError.message("\(name) must be positive")
210209
}
211210
return value
212211
}
213212

214-
private func takeNonNegativeInt(_ arguments: inout [String], _ name: String) throws -> Int {
215-
guard let rawValue = arguments.first else {
213+
private func takeNonNegativeInt(_ arguments: inout ArraySlice<String>, _ name: String) throws -> Int
214+
{
215+
guard let rawValue = arguments.popFirst() else {
216216
throw ProbeError.message("missing value for \(name)")
217217
}
218-
arguments.removeFirst()
219218
guard let value = Int(rawValue), value >= 0 else {
220219
throw ProbeError.message("\(name) must be a non-negative integer")
221220
}
@@ -249,8 +248,7 @@ private func makeRewriteInput(event: CGEvent, configuration: AppConfiguration) -
249248
let decision = ScrollRewriteCore.decidePrecision(
250249
isOptionHeld: originalFlags.contains(.maskAlternate),
251250
isOptionPrecisionEnabled: configuration.isOptionPrecisionEnabled,
252-
isTerminalFrontmost: false,
253-
isTerminalDefaultPrecisionEnabled: configuration.isTerminalDefaultPrecisionEnabled
251+
isTerminalOptimizationActive: false
254252
)
255253

256254
return ScrollRewriteInput(

0 commit comments

Comments
 (0)