Skip to content

perf: avoid redundant character counting in test stats calculation #8079

@rohanghosal04

Description

@rohanghosal04

Did you clear cache before opening an issue?

  • I have cleared my cache

Is there an existing issue for this?

  • I have searched the existing open and closed issues

Does the issue happen when logged in?

Yes

Does the issue happen when logged out?

Yes

Does the issue happen in incognito mode when logged in?

Yes

Does the issue happen in incognito mode when logged out?

Yes

Account name

No response

Account config

No response

Current Behavior

In frontend/src/ts/test/test-stats.ts, the calculateResultStats function currently iterates over the test text twice to calculate characters, once in countChars() and again inside calculateWpmAndRaw(). Both countChars(true) and calculateWpmAndRaw(true, true, testSeconds) are called consecutively, causing redundant loops over the same text data.

Expected Behavior

The character counting should be optimized so the iteration only happens once. The chars object calculated by countChars could be passed to calculateWpmAndRaw so it doesn't have to recalculate it internally.

Steps To Reproduce

  1. Open the repository locally or on GitHub.
  2. Navigate to frontend/src/ts/test/test-stats.ts.
  3. Go to line 344.
  4. Notice the existing //todo: this counts chars twice - once here and once in calculateWpmAndRaw comment.

Environment

  • OS: WIndows 11
  • Browser: Google Chrome
  • Browser Version: 148.0.7778.179 (Official Build) (64-bit)

Anything else?

I would love to be assigned to this issue and submit a PR to fix it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions