-
Notifications
You must be signed in to change notification settings - Fork 440
Description
Summary
Comments in Gno source code increase gas costs not only at deployment (expected) but also at runtime during the first function call to a realm. This creates a disincentive for developers to include documentation in their contracts.
Problem
Expected behavior: Comments should only affect deployment cost (storage), not runtime execution cost.
Actual behavior: Comments increase gas cost on the first call to a realm within a transaction, likely due to realm loading/parsing overhead.
Benchmark Results
Deployment Cost
| Realm | Comment Level | Gas Cost | vs Baseline |
|---|---|---|---|
| nocomment | None | 328,452 | baseline |
| withcomment | Normal | 343,204 | +4.5% |
| heavycomment | Heavy | 390,698 | +18.9% |
This is acceptable - more comments = more storage on blockchain nodes.
Runtime Cost - First Call
| Realm | Gas Cost | vs Baseline |
|---|---|---|
| nocomment | 307,338 | baseline |
| withcomment | 308,796 | +0.5% |
| heavycomment | 309,602 | +0.7% |
This is problematic - users pay extra gas due to comments they don't control.
Runtime Cost - Subsequent Calls (Same TX)
| Realm | 2 calls | 5 calls | Additional cost per call |
|---|---|---|---|
| nocomment | 309,297 | 314,016 | ~980 |
| heavycomment | 311,555 | 316,274 | ~977 |
After the first call, subsequent calls show no difference regardless of comment level. This suggests comments are parsed/loaded only once and cached.
Analysis
The runtime gas difference appears during the initial realm load. Once loaded, the realm is cached and comments no longer affect gas costs. This indicates that:
- Source code (including comments) is being parsed at runtime
- The parsing cost is proportional to code size (including comments)
- Caching prevents repeated parsing within the same transaction
Concern
If runtime gas costs are affected by comments:
- Developers will strip comments to reduce user costs
- Code readability on-chain suffers
- This undermines Gno's value proposition as transparent, readable smart contracts
Suggestion
Consider separating comment handling so that:
- Deployment: Full source stored (comments included) - gas cost reflects storage
- Runtime: Only executable code affects gas metering - comments excluded from load cost
Reproduction
Test contracts and measurement scripts available at:
https://github.com/gnoswap-labs/gnoswap/blob/main/tests/integration/testdata/base/comment_gas_measurement.txtar
Metadata
Metadata
Assignees
Labels
Type
Projects
Status