Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: parser & cloze patterns #1117

Merged
merged 1 commit into from
Oct 13, 2024
Merged

refactor: parser & cloze patterns #1117

merged 1 commit into from
Oct 13, 2024

Conversation

st3v3nmw
Copy link
Owner

@st3v3nmw st3v3nmw commented Oct 13, 2024

Updating the parser to use peggy has slowed the plugin drastically (See #1115, #1111, & #1110). This change refactors the parser to one written by hand compared to an auto-generated one. I think this is the better approach for performance reasons & it's sad that we have to undo all the work that went into #1012.

I've tried to replicate the existing behavior as closely as possible with the new parser including the multiline cards with spaces introduced in #1012.

On the brighter side, we've switched parsing of cloze cards to use @MotaOcimar's clozecraft package from #943.

@st3v3nmw
Copy link
Owner Author

st3v3nmw commented Oct 13, 2024

This PR definitely improves the parser's performance:

CI run before:

PASS tests/unit/parser.test.ts
  ✓ Test parsing of single line basic cards (353 ms)
  ✓ Test parsing of single line reversed cards (179 ms)
  ✓ Test parsing of multi line basic cards (312 ms)
  ✓ Test parsing of multi line reversed cards (290 ms)
  ✓ Test parsing of cloze cards (420 ms)
  ✓ Test parsing of a mix of card types (33 ms)
  ✓ Test parsing cards with codeblocks (2 ms)
  ✓ Test not parsing cards in HTML comments (1 ms)
  ✓ Test not parsing 'cards' in codeblocks (144 ms)

CI run after:

 PASS tests/unit/parser.test.ts
  ✓ Test parsing of single line basic cards (4 ms)
  ✓ Test parsing of single line reversed cards (2 ms)
  ✓ Test parsing of multi line basic cards (5 ms)
  ✓ Test parsing of multi line reversed cards (2 ms)
  ✓ Test parsing of cloze cards (8 ms)
  ✓ Test parsing of a mix of card types (1 ms)
  ✓ Test parsing cards with codeblocks (1 ms)
  ✓ Test not parsing cards in HTML comments (2 ms)
  ✓ Test not parsing 'cards' in codeblocks (1 ms)

@st3v3nmw st3v3nmw force-pushed the fix-parser-performance branch 2 times, most recently from 632f550 to f3f690d Compare October 13, 2024 16:32
@st3v3nmw st3v3nmw force-pushed the fix-parser-performance branch from f3f690d to 241a59a Compare October 13, 2024 16:40
@st3v3nmw st3v3nmw merged commit 315cad8 into master Oct 13, 2024
3 checks passed
@st3v3nmw st3v3nmw deleted the fix-parser-performance branch October 13, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant