Copilot commented on code in PR #167:
URL:
https://github.com/apache/skywalking-client-js/pull/167#discussion_r2579333076
##########
src/performance/index.ts:
##########
@@ -214,7 +214,7 @@ class TracePerf {
const param = {
inpTime: interaction.latency,
Review Comment:
The comparison logic is inconsistent with the value being pushed. On line
213, the comparison uses `Math.floor(interaction.latency)`, but on line 215,
the actual value stored is `interaction.latency` (without flooring). This means
the comparison may not prevent duplicates correctly.
The value should be floored before assignment to maintain consistency:
```typescript
const param = {
inpTime: Math.floor(interaction.latency),
...this.perfInfo,
} as INPListItem;
```
```suggestion
inpTime: Math.floor(interaction.latency),
```
##########
src/performance/index.ts:
##########
@@ -242,7 +242,10 @@ class TracePerf {
if (!this.inpList.length) {
return;
}
-
+ this.inpList = this.inpList.map((item: INPListItem) => ({
+ ...item,
+ inpTime: item.inpTime > 1 ? Math.floor(item.inpTime) :
Math.round(item.inpTime),
+ }));
Review Comment:
The rounding logic here is redundant and inconsistent with the rest of the
codebase. Since `inpTime` is already being floored at line 215 when the value
is added to the list, this transformation in `reportINP()` is unnecessary.
Additionally, the condition `> 1` is unusual - CLS values are typically
between 0 and 1, but INP values (interaction latency) are measured in
milliseconds and are typically much larger than 1. The logic here doesn't align
with the metric's characteristics.
For consistency with other metrics like LCP (line 180) and resource
durations (lines 91, 106), this should simply use `Math.floor()` without
conditions. However, if line 215 is fixed to floor the value when it's added,
this entire map operation becomes unnecessary and should be removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]