v0.3.0 d226234

data-model.md RawHistoryFolder

Data Model: WebKit Memory Optimization

Feature: 005-webkit-memory-optimization Phase: 1 - Design & Data Model Date: 2025-01-10

Core Entities

MemoryConfig

Purpose: Configuration settings that control WebKit memory optimization behavior

Fields:

  • MemoryLimitMB (int): Maximum memory limit per WebView in MB (0 = unlimited)
  • ConservativeThreshold (float64): Early memory cleanup threshold (0.0-1.0, default 0.33)
  • StrictThreshold (float64): Aggressive memory cleanup threshold (0.0-1.0, default 0.5)
  • KillThreshold (float64): Process termination threshold (0.0-1.0, 0 = disabled)
  • PollIntervalSeconds (float64): Memory usage polling interval (default 2.0)
  • CacheModel (CacheModel): WebKit caching strategy (document_viewer/web_browser/primary_web_browser)
  • EnablePageCache (bool): Enable/disable page cache for back/forward navigation
  • EnableOfflineAppCache (bool): Enable/disable offline application caching
  • ProcessRecycleThreshold (int): Recycle WebView after N page loads (0 = disabled)
  • EnableGCInterval (int): JavaScript garbage collection interval in seconds (0 = disabled)
  • EnableMemoryMonitoring (bool): Enable detailed memory logging and monitoring

Validation Rules:

  • ConservativeThreshold must be between 0.0 and 1.0
  • StrictThreshold must be between 0.0 and 1.0
  • StrictThreshold must be greater than ConservativeThreshold
  • KillThreshold must be between 0.0 and 1.0
  • PollIntervalSeconds must be non-negative
  • MemoryLimitMB must be non-negative

State Transitions: Immutable configuration object (changes require new instance)

MemoryStats

Purpose: Real-time and historical memory usage statistics for WebView instances

Fields:

  • pageLoadCount (int): Number of pages loaded in this WebView instance
  • lastGCTime (time.Time): Timestamp of last JavaScript garbage collection
  • memoryPressureSettings (*C.WebKitMemoryPressureSettings): Native WebKit memory settings

Relationships:

  • Owned by WebView instance (1:1 relationship)
  • References native WebKit memory pressure settings
  • Tracked by WebViewMemoryManager (many:1 relationship)

Validation Rules: Read-only statistics, no validation required

State Transitions:

  • pageLoadCount increments on each page load
  • lastGCTime updates when garbage collection is triggered
  • memoryPressureSettings set once during WebView creation

ProcessMemoryInfo

Purpose: System-level memory information for WebKit processes

Fields:

  • PID (int): Process identifier
  • VmRSS (int64): Resident Set Size in KB (actual RAM usage)
  • VmSize (int64): Virtual Memory Size in KB (total virtual memory)
  • VmPeak (int64): Peak Virtual Memory in KB (maximum ever used)
  • ProcessName (string): Name of the process (extracted from cmdline)

Relationships:

  • Collected by WebViewMemoryManager for all WebKit processes
  • Associated with specific WebView instances (many:1 for multi-process WebKit)

Validation Rules:

  • All memory values must be non-negative
  • PID must be positive integer

State Transitions: Immutable snapshot of process memory state

OptimizationPreset

Purpose: Pre-configured memory optimization settings for common use cases

Fields: Embeds MemoryConfig with preset values

Preset Types:

  1. MemoryOptimized: Maximum memory reduction (256MB limit, aggressive thresholds)
  2. Balanced: Moderate optimization (512MB limit, balanced thresholds)
  3. HighPerformance: Maximum performance (no limits, minimal optimization)

Validation Rules: Inherits MemoryConfig validation rules

State Transitions: Immutable preset definitions

WebViewMemoryManager

Purpose: Global memory monitoring and lifecycle management for multiple WebViews

Fields:

  • views (map[uintptr]*WebView): Registry of active WebViews by ID
  • enableMonitoring (bool): Enable background memory monitoring
  • recycleThreshold (int): Global recycling threshold
  • monitoringInterval (time.Duration): Monitoring check frequency
  • stopMonitoring (chan struct{}): Channel for stopping monitoring goroutine

Relationships:

  • Manages multiple WebView instances (1:many)
  • Monitors ProcessMemoryInfo for all WebKit processes
  • Singleton pattern for global memory management

Validation Rules:

  • monitoringInterval must be positive
  • recycleThreshold must be non-negative

State Transitions:

  • WebViews registered on creation, unregistered on destruction
  • Monitoring starts when first WebView registered
  • Monitoring stops when last WebView unregistered

Entity Relationships

WebView (1) ----owns----> (1) MemoryStats
   |                           |
   |                           |
   v                           v
WebViewMemoryManager <-tracks- ProcessMemoryInfo
   |
   |
   v (configures)
MemoryConfig <-preset- OptimizationPreset

Data Flow

Memory Configuration Flow

  1. User selects optimization preset or custom settings
  2. MemoryConfig validated and applied to WebView creation
  3. WebKit memory pressure settings configured via C API
  4. Settings persisted for process lifecycle

Memory Monitoring Flow

  1. WebViewMemoryManager polls /proc filesystem for process memory
  2. WebKit memory pressure callbacks trigger on internal events
  3. MemoryStats updated with current usage and GC events
  4. Memory events logged if monitoring enabled

Process Recycling Flow

  1. MemoryStats.pageLoadCount incremented on navigation
  2. WebViewMemoryManager checks recycling threshold
  3. Recycling recommendation logged (user/application decision)
  4. New WebView creation triggers fresh memory allocation

Memory Layout Considerations

Go Memory Management

  • WebView structs include finalizers for cleanup
  • CGO memory requires explicit free() calls
  • Channel-based coordination for goroutine cleanup
  • Careful pointer management for C callbacks

WebKit Native Memory

  • WebKitMemoryPressureSettings allocated via C API
  • GObject reference counting for WebKit objects
  • Memory pressure thresholds enforced by WebKit internally
  • Process memory isolated per WebView instance

Monitoring Memory Overhead

  • /proc parsing: ~1KB per process check
  • Memory statistics storage: ~100 bytes per WebView
  • Monitoring goroutine: ~8KB stack space
  • Logging overhead: configurable via EnableMemoryMonitoring flag

Testing Considerations

Unit Tests

  • MemoryConfig validation rules
  • OptimizationPreset value correctness
  • ProcessMemoryInfo parsing accuracy
  • WebViewMemoryManager lifecycle management

Integration Tests

  • WebKit memory pressure settings application
  • Real memory usage reduction measurement
  • Process recycling effectiveness
  • Memory monitoring accuracy vs /proc ground truth

Contract Tests

  • WebKit C API memory functions available
  • Memory pressure callbacks functional
  • GObject reference counting correct
  • CGO memory safety verified
source
1# Data Model: WebKit Memory Optimization
2
3**Feature**: 005-webkit-memory-optimization
4**Phase**: 1 - Design & Data Model
5**Date**: 2025-01-10
6
7## Core Entities
8
9### MemoryConfig
10**Purpose**: Configuration settings that control WebKit memory optimization behavior
11
12**Fields**:
13- `MemoryLimitMB` (int): Maximum memory limit per WebView in MB (0 = unlimited)
14- `ConservativeThreshold` (float64): Early memory cleanup threshold (0.0-1.0, default 0.33)
15- `StrictThreshold` (float64): Aggressive memory cleanup threshold (0.0-1.0, default 0.5)
16- `KillThreshold` (float64): Process termination threshold (0.0-1.0, 0 = disabled)
17- `PollIntervalSeconds` (float64): Memory usage polling interval (default 2.0)
18- `CacheModel` (CacheModel): WebKit caching strategy (document_viewer/web_browser/primary_web_browser)
19- `EnablePageCache` (bool): Enable/disable page cache for back/forward navigation
20- `EnableOfflineAppCache` (bool): Enable/disable offline application caching
21- `ProcessRecycleThreshold` (int): Recycle WebView after N page loads (0 = disabled)
22- `EnableGCInterval` (int): JavaScript garbage collection interval in seconds (0 = disabled)
23- `EnableMemoryMonitoring` (bool): Enable detailed memory logging and monitoring
24
25**Validation Rules**:
26- ConservativeThreshold must be between 0.0 and 1.0
27- StrictThreshold must be between 0.0 and 1.0
28- StrictThreshold must be greater than ConservativeThreshold
29- KillThreshold must be between 0.0 and 1.0
30- PollIntervalSeconds must be non-negative
31- MemoryLimitMB must be non-negative
32
33**State Transitions**: Immutable configuration object (changes require new instance)
34
35### MemoryStats
36**Purpose**: Real-time and historical memory usage statistics for WebView instances
37
38**Fields**:
39- `pageLoadCount` (int): Number of pages loaded in this WebView instance
40- `lastGCTime` (time.Time): Timestamp of last JavaScript garbage collection
41- `memoryPressureSettings` (*C.WebKitMemoryPressureSettings): Native WebKit memory settings
42
43**Relationships**: 
44- Owned by WebView instance (1:1 relationship)
45- References native WebKit memory pressure settings
46- Tracked by WebViewMemoryManager (many:1 relationship)
47
48**Validation Rules**: Read-only statistics, no validation required
49
50**State Transitions**:
51- `pageLoadCount` increments on each page load
52- `lastGCTime` updates when garbage collection is triggered
53- `memoryPressureSettings` set once during WebView creation
54
55### ProcessMemoryInfo
56**Purpose**: System-level memory information for WebKit processes
57
58**Fields**:
59- `PID` (int): Process identifier
60- `VmRSS` (int64): Resident Set Size in KB (actual RAM usage)
61- `VmSize` (int64): Virtual Memory Size in KB (total virtual memory)
62- `VmPeak` (int64): Peak Virtual Memory in KB (maximum ever used)
63- `ProcessName` (string): Name of the process (extracted from cmdline)
64
65**Relationships**: 
66- Collected by WebViewMemoryManager for all WebKit processes
67- Associated with specific WebView instances (many:1 for multi-process WebKit)
68
69**Validation Rules**:
70- All memory values must be non-negative
71- PID must be positive integer
72
73**State Transitions**: Immutable snapshot of process memory state
74
75### OptimizationPreset
76**Purpose**: Pre-configured memory optimization settings for common use cases
77
78**Fields**: Embeds MemoryConfig with preset values
79
80**Preset Types**:
811. **MemoryOptimized**: Maximum memory reduction (256MB limit, aggressive thresholds)
822. **Balanced**: Moderate optimization (512MB limit, balanced thresholds)  
833. **HighPerformance**: Maximum performance (no limits, minimal optimization)
84
85**Validation Rules**: Inherits MemoryConfig validation rules
86
87**State Transitions**: Immutable preset definitions
88
89### WebViewMemoryManager
90**Purpose**: Global memory monitoring and lifecycle management for multiple WebViews
91
92**Fields**:
93- `views` (map[uintptr]*WebView): Registry of active WebViews by ID
94- `enableMonitoring` (bool): Enable background memory monitoring
95- `recycleThreshold` (int): Global recycling threshold
96- `monitoringInterval` (time.Duration): Monitoring check frequency
97- `stopMonitoring` (chan struct{}): Channel for stopping monitoring goroutine
98
99**Relationships**:
100- Manages multiple WebView instances (1:many)
101- Monitors ProcessMemoryInfo for all WebKit processes
102- Singleton pattern for global memory management
103
104**Validation Rules**:
105- monitoringInterval must be positive
106- recycleThreshold must be non-negative
107
108**State Transitions**:
109- WebViews registered on creation, unregistered on destruction
110- Monitoring starts when first WebView registered
111- Monitoring stops when last WebView unregistered
112
113## Entity Relationships
114
115```
116WebView (1) ----owns----> (1) MemoryStats
117   |                           |
118   |                           |
119   v                           v
120WebViewMemoryManager <-tracks- ProcessMemoryInfo
121   |
122   |
123   v (configures)
124MemoryConfig <-preset- OptimizationPreset
125```
126
127## Data Flow
128
129### Memory Configuration Flow
1301. User selects optimization preset or custom settings
1312. MemoryConfig validated and applied to WebView creation
1323. WebKit memory pressure settings configured via C API
1334. Settings persisted for process lifecycle
134
135### Memory Monitoring Flow
1361. WebViewMemoryManager polls /proc filesystem for process memory
1372. WebKit memory pressure callbacks trigger on internal events
1383. MemoryStats updated with current usage and GC events
1394. Memory events logged if monitoring enabled
140
141### Process Recycling Flow
1421. MemoryStats.pageLoadCount incremented on navigation
1432. WebViewMemoryManager checks recycling threshold
1443. Recycling recommendation logged (user/application decision)
1454. New WebView creation triggers fresh memory allocation
146
147## Memory Layout Considerations
148
149### Go Memory Management
150- WebView structs include finalizers for cleanup
151- CGO memory requires explicit free() calls
152- Channel-based coordination for goroutine cleanup
153- Careful pointer management for C callbacks
154
155### WebKit Native Memory
156- WebKitMemoryPressureSettings allocated via C API
157- GObject reference counting for WebKit objects
158- Memory pressure thresholds enforced by WebKit internally
159- Process memory isolated per WebView instance
160
161### Monitoring Memory Overhead
162- /proc parsing: ~1KB per process check
163- Memory statistics storage: ~100 bytes per WebView
164- Monitoring goroutine: ~8KB stack space
165- Logging overhead: configurable via EnableMemoryMonitoring flag
166
167## Testing Considerations
168
169### Unit Tests
170- MemoryConfig validation rules
171- OptimizationPreset value correctness
172- ProcessMemoryInfo parsing accuracy
173- WebViewMemoryManager lifecycle management
174
175### Integration Tests
176- WebKit memory pressure settings application
177- Real memory usage reduction measurement
178- Process recycling effectiveness
179- Memory monitoring accuracy vs /proc ground truth
180
181### Contract Tests
182- WebKit C API memory functions available
183- Memory pressure callbacks functional
184- GObject reference counting correct
185- CGO memory safety verified

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close