Skip to content

Commit 40fe504

Browse files
committed
Squash all commits into one for GitHub Actions CI/CD optimization
Consolidating 23 commits into a single commit to improve CI/CD pipeline performance and reduce workflow execution time on GitHub Actions. Multiple commits were causing excessive workflow runs and slowing down automated testing and deployment processes.
0 parents  commit 40fe504

21 files changed

+4089
-0
lines changed

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
ecmaVersion: 2020,
6+
sourceType: 'module',
7+
},
8+
plugins: ['@typescript-eslint'],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
rules: {
14+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
15+
'@typescript-eslint/no-explicit-any': 'warn',
16+
},
17+
};

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
out/
3+
.vscode-test/
4+
*.vsix
5+
.DS_Store

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run Extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"args": [
9+
"--extensionDevelopmentPath=${workspaceFolder}"
10+
],
11+
"outFiles": [
12+
"${workspaceFolder}/out/**/*.js"
13+
],
14+
"sourceMaps": true
15+
}
16+
]
17+
}

.vscode/tasks.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "compile",
7+
"problemMatcher": "$tsc",
8+
"presentation": {
9+
"reveal": "silent"
10+
},
11+
"group": {
12+
"kind": "build",
13+
"isDefault": true
14+
}
15+
},
16+
{
17+
"type": "npm",
18+
"script": "watch",
19+
"problemMatcher": "$tsc-watch",
20+
"isBackground": true,
21+
"presentation": {
22+
"reveal": "never"
23+
}
24+
}
25+
]
26+
}

.vscodeignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.vscode/**
2+
.vscode-test/**
3+
src/**
4+
.gitignore
5+
.eslintrc.js
6+
tsconfig.json
7+
**/*.map
8+
**/*.ts
9+
!out/**/*.js
10+
node_modules/**
11+
examples/**
12+
DEVELOPMENT.md
13+
TESTING.md
14+
go-memory-visualizer.code-workspace
15+
*.log
16+
out/test/**

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Changelog
2+
3+
All notable changes to the Go Memory Layout Visualizer extension will be documented in this file.
4+
5+
## [0.1.0] - 2025-11-21
6+
7+
### Added
8+
- Initial release
9+
- Real-time memory layout visualization for Go structs
10+
- Inline annotations showing byte offsets, sizes, and padding
11+
- Multi-architecture support (amd64, arm64, 386)
12+
- Hover provider with detailed field information
13+
- CodeLens provider for one-click struct optimization
14+
- Automatic field reordering to minimize memory usage
15+
- Padding detection and highlighting
16+
- Commands:
17+
- `Go: Optimize Struct Memory Layout`
18+
- `Go: Show Memory Layout`
19+
- `Go: Toggle Architecture`
20+
- Configuration options:
21+
- Default architecture selection
22+
- Toggle inline annotations
23+
- Padding warning threshold
24+
- Cache line warnings
25+
26+
### Features
27+
- Supports all Go primitive types (bool, int8-64, uint8-64, float32/64, complex64/128)
28+
- Handles pointers, slices, arrays, maps, channels, interfaces
29+
- Smart field ordering by alignment and size
30+
- Visual padding warnings with configurable thresholds
31+
- Side-by-side memory layout comparison panel
32+
- Comprehensive test coverage for calculator, parser, and optimizer
33+
34+
### Technical Details
35+
- Built with TypeScript
36+
- Zero external runtime dependencies
37+
- Full test suite with 30+ test cases
38+
- Follows Go's memory layout rules precisely
39+
- Accurate padding calculation
40+
- Support for embedded fields and complex types

DEMO.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Go Memory Layout Visualizer - Live Demo
2+
3+
## What It Does
4+
5+
Visualizes Go struct memory layouts in real-time showing offsets, sizes, alignment, and padding waste.
6+
7+
## Features in Action
8+
9+
### 1. Real-Time Inline Annotations
10+
11+
```go
12+
type User struct {
13+
// offset: 0 | size: 1 | align: 1 | padding: 7
14+
Active bool
15+
16+
// offset: 8 | size: 8 | align: 8 | padding: 0
17+
ID uint64
18+
}
19+
```
20+
21+
### 2. One-Click Optimization
22+
23+
CodeLens shows: `Optimize struct - save 14 bytes (29% reduction)`
24+
25+
Click it to automatically reorder fields optimally.
26+
27+
### 3. Hover Details
28+
29+
Hover any field to see:
30+
- Complete memory layout
31+
- Optimization suggestions
32+
- Performance impact
33+
34+
### 4. Padding Warnings
35+
36+
Fields with excessive padding highlighted in yellow/orange.
37+
38+
### 5. Multi-Architecture
39+
40+
Toggle between amd64, arm64, and 386 to see different layouts.
41+
42+
## Real-World Examples
43+
44+
See `examples/demonstration.go` for 10 complete examples including:
45+
- User profiles (29% to 15% waste)
46+
- API responses (21% to 6% waste)
47+
- Database models (22% to 11% waste)
48+
- Network protocols (37% to 17% waste)
49+
50+
## Commands
51+
52+
- `Go: Show Memory Layout` - Full breakdown
53+
- `Go: Optimize Struct` - Reorder fields
54+
- `Go: Toggle Architecture` - Switch platforms
55+
56+
Ready to save memory and improve cache efficiency!

DEVELOPMENT.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Development Guide
2+
3+
## Setup
4+
5+
1. Install dependencies:
6+
```bash
7+
npm install
8+
```
9+
10+
2. Compile TypeScript:
11+
```bash
12+
npm run compile
13+
```
14+
15+
3. Run tests:
16+
```bash
17+
node out/test/memoryCalculator.test.js
18+
node out/test/goParser.test.js
19+
node out/test/optimizer.test.js
20+
```
21+
22+
## Running the Extension
23+
24+
### Option 1: Debug in VS Code
25+
1. Open this folder in VS Code
26+
2. Press F5 to launch Extension Development Host
27+
3. Open a Go file (try `examples/structs.go`)
28+
4. See inline memory annotations above struct fields
29+
5. Hover over fields for detailed info
30+
6. Click CodeLens "Optimize Layout" button above structs
31+
32+
### Option 2: Package and Install
33+
```bash
34+
npm install -g @vscode/vsce
35+
vsce package
36+
code --install-extension go-memory-visualizer-0.1.0.vsix
37+
```
38+
39+
## Features to Test
40+
41+
### 1. Inline Annotations
42+
- Open `examples/structs.go`
43+
- You should see annotations like `[0-7] 8B` above each field
44+
- Fields with padding show `+7B padding [!]`
45+
46+
### 2. Hover Information
47+
- Hover over any struct field
48+
- See detailed breakdown:
49+
- Type, offset, size, alignment
50+
- Padding warnings
51+
52+
### 3. CodeLens Optimization
53+
- Look for `Optimize Layout (save XB)` above poorly ordered structs
54+
- Click to automatically reorder fields
55+
- See confirmation message with bytes saved
56+
57+
### 4. Commands
58+
- `Ctrl+Shift+P` → "Go: Show Memory Layout"
59+
- Opens side panel with full memory breakdown table
60+
- `Ctrl+Shift+P` → "Go: Toggle Architecture"
61+
- Switch between amd64, arm64, 386
62+
- Recalculates layouts for selected architecture
63+
- `Ctrl+Shift+P` → "Go: Optimize Struct Memory Layout"
64+
- Optimizes struct under cursor
65+
66+
### 5. Architecture Support
67+
- Test with different architectures
68+
- Note how pointer/int sizes change between 386 (32-bit) and amd64/arm64 (64-bit)
69+
70+
## Configuration
71+
72+
Settings in `.vscode/settings.json`:
73+
```json
74+
{
75+
"goMemoryVisualizer.defaultArchitecture": "amd64",
76+
"goMemoryVisualizer.showInlineAnnotations": true,
77+
"goMemoryVisualizer.highlightPadding": true,
78+
"goMemoryVisualizer.paddingWarningThreshold": 8,
79+
"goMemoryVisualizer.showCacheLineWarnings": true
80+
}
81+
```
82+
83+
## Architecture
84+
85+
```
86+
src/
87+
├── types.ts - TypeScript interfaces
88+
├── memoryCalculator.ts - Core memory layout logic
89+
├── goParser.ts - Go AST parsing
90+
├── optimizer.ts - Struct field reordering
91+
├── extension.ts - VS Code integration
92+
└── test/
93+
├── memoryCalculator.test.ts
94+
├── goParser.test.ts
95+
└── optimizer.test.ts
96+
```
97+
98+
## Memory Layout Rules
99+
100+
### Go Type Sizes (amd64)
101+
- `bool`, `int8`, `uint8`, `byte`: 1 byte
102+
- `int16`, `uint16`: 2 bytes
103+
- `int32`, `uint32`, `float32`, `rune`: 4 bytes
104+
- `int64`, `uint64`, `float64`: 8 bytes
105+
- `int`, `uint`, `uintptr`, `*T`: 8 bytes (pointer size)
106+
- `string`: 16 bytes (pointer + length)
107+
- `[]T`: 8 bytes (slice header pointer)
108+
- `interface{}`: 16 bytes (type + data pointers)
109+
110+
### Alignment Rules
111+
- Fields are aligned to their natural alignment
112+
- Structs are aligned to their largest field alignment
113+
- Padding is added to maintain alignment
114+
115+
### Optimization Strategy
116+
1. Sort fields by alignment (descending)
117+
2. Within same alignment, sort by size (descending)
118+
3. This minimizes padding between fields
119+
120+
## Troubleshooting
121+
122+
### No decorations showing
123+
- Check `goMemoryVisualizer.showInlineAnnotations` is `true`
124+
- Verify file language is `Go`
125+
- Try reloading VS Code window
126+
127+
### Wrong sizes displayed
128+
- Check selected architecture matches your target
129+
- Use `Go: Toggle Architecture` command
130+
131+
### Tests failing
132+
- Run `npm run compile` first
133+
- Check Node.js version (requires 20.x)
134+
135+
## Publishing
136+
137+
1. Update version in `package.json`
138+
2. Update `README.md` and `CHANGELOG.md`
139+
3. Run tests: `npm test`
140+
4. Package: `vsce package`
141+
5. Publish: `vsce publish`
142+
143+
## Future Enhancements
144+
145+
- [ ] Cache line boundary visualization
146+
- [ ] Support for embedded structs
147+
- [ ] Comparison view (before/after optimization)
148+
- [ ] Export memory layout reports
149+
- [ ] Integration with Go's `unsafe.Sizeof`
150+
- [ ] Benchmark impact visualization

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Go Memory Layout Visualizer Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)