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

feat: use PackageClauseOnly for parsing pkg name #994

Merged
merged 4 commits into from
Aug 10, 2023

Conversation

harry-hov
Copy link
Contributor

Previously, we were parsing the whole file using MustParseFile(), which uses Go2Gno(), and incurred unnecessary overhead. This PR modifies the func PackageNameFromFileBody() to use mode PackageClauseOnly, which extracts the package name without the need for heavier parsing operations.

Contributors Checklist

  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jul 26, 2023
@harry-hov harry-hov marked this pull request as ready for review July 26, 2023 13:55
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 💯

Left some minor comments

gnovm/pkg/gnolang/nodes.go Show resolved Hide resolved
gnovm/pkg/gnolang/nodes.go Show resolved Hide resolved
@moul
Copy link
Member

moul commented Aug 10, 2023

I suggest favoring parsing over regex, even though regex may have optimization benefits in some cases.

For the future, I recommend building a (lazy?) caching system (around memFile?). This could involve parsing and caching the file lazily, allowing specialized helper functions to navigate the AST and avoid double parsing.

@moul moul merged commit b884a6e into gnolang:master Aug 10, 2023
47 checks passed
Doozers pushed a commit to Doozers/gno that referenced this pull request Aug 31, 2023
@moul moul added this to the 💡Someday/Maybe milestone Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants