LearnNewsExamplesServices
Frontmatter
id7159
titleOptimize Build Process with a Pre-emptive Regex Check
stateClosed
labels
enhancement
assigneestobiu
createdAtAug 2, 2025, 1:29 PM
updatedAtAug 2, 2025, 2:00 PM
githubUrlhttps://github.com/neomjs/neo/issues/7159
authortobiu
commentsCount0
parentIssue7130
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtAug 2, 2025, 2:00 PM

Optimize Build Process with a Pre-emptive Regex Check

Closed v10.3.0 enhancement
tobiu
tobiu commented on Aug 2, 2025, 1:29 PM

1. Summary

Before running the full, expensive AST parsing pipeline on a file, perform a quick regular expression check to see if the file likely contains an html template.

2. Rationale

The current process parses every single .mjs file with acorn, which is computationally expensive. The vast majority of files in the project do not use html templates. By adding a quick pre-check, we can skip the entire AST transformation process for most files, significantly speeding up the overall build time.

3. Scope & Implementation Plan

  1. Define Regex: Create a simple, fast regex (e.g., /html\s*/`) to detect the presence of a tagged template literal.
  2. Implement Check: In buildESModules.mjs, inside the minifyFile function, add a conditional check:
    • if (regex.test(content)) { ... }
  3. Conditional Processing: Only if the regex test passes, call the processFileContent() function from the new astTemplateProcessor. If it fails, the content can be passed directly to the next step (Terser minification).

4. Definition of Done

  • The regex check is implemented in buildESModules.mjs.
  • Files that do not contain html templates are no longer processed by the astTemplateProcessor.
  • Files that do contain html templates are still transformed correctly.
  • The overall build time is measurably reduced.
tobiu assigned to @tobiu on Aug 2, 2025, 1:29 PM
tobiu added the enhancement label on Aug 2, 2025, 1:29 PM
tobiu added parent issue #7130 on Aug 2, 2025, 1:29 PM
tobiu cross-referenced by #7160 on Aug 2, 2025, 1:31 PM
tobiu referenced in commit 4945297 - "Optimize Build Process with a Pre-emptive Regex Check #7159" on Aug 2, 2025, 1:59 PM
tobiu closed this issue on Aug 2, 2025, 2:00 PM