Skip to content

Commit 0ace59e

Browse files
committed
wasm: simplify platform-specific page size handling
Replace os.Getpagesize() calls with common.DefaultPageSize constant and remove redundant pagesize.go implementation. Simplify WASM-specific code by removing custom initialization and page size handling. Update tests to use the new constant. Signed-off-by: Travis Cline <[email protected]>
1 parent 55aec40 commit 0ace59e

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

db.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,13 @@ func (db *DB) beginTx() (*Tx, error) {
784784
// write transaction will obtain them.
785785
db.metalock.Lock()
786786

787-
// Allow platform-specific transaction initialization
788-
if initer, ok := any(db).(txIniter); ok {
789-
if err := initer.txInit(); err != nil {
790-
db.metalock.Unlock()
791-
return nil, err
787+
// Allow WASM-specific transaction initialization
788+
if runtime.GOARCH == "wasm" {
789+
if initer, ok := any(db).(txIniter); ok {
790+
if err := initer.txInit(); err != nil {
791+
db.metalock.Unlock()
792+
return nil, err
793+
}
792794
}
793795
}
794796

@@ -849,11 +851,13 @@ func (db *DB) beginRWTx() (*Tx, error) {
849851
db.metalock.Lock()
850852
defer db.metalock.Unlock()
851853

852-
// Allow platform-specific transaction initialization
853-
if initer, ok := any(db).(txIniter); ok {
854-
if err := initer.txInit(); err != nil {
855-
db.rwlock.Unlock()
856-
return nil, err
854+
// Allow WASM-specific transaction initialization
855+
if runtime.GOARCH == "wasm" {
856+
if initer, ok := any(db).(txIniter); ok {
857+
if err := initer.txInit(); err != nil {
858+
db.rwlock.Unlock()
859+
return nil, err
860+
}
857861
}
858862
}
859863

db_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
bolt "go.etcd.io/bbolt"
2525
berrors "go.etcd.io/bbolt/errors"
2626
"go.etcd.io/bbolt/internal/btesting"
27-
"go.etcd.io/bbolt/internal/common"
2827
)
2928

3029
// pageSize is the size of one page in the data file.
@@ -241,7 +240,7 @@ func TestOpen_ReadPageSize_FromMeta1_OS(t *testing.T) {
241240

242241
// Reopen data file.
243242
db = btesting.MustOpenDBWithOption(t, path, nil)
244-
require.Equalf(t, common.GetPagesize(), db.Info().PageSize, "check page size failed")
243+
require.Equalf(t, os.Getpagesize(), db.Info().PageSize, "check page size failed")
245244
}
246245

247246
// Ensure that it can read the page size from the second meta page if the first one is invalid.

internal/common/bolt_wasm.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33
package common
44

55
// MaxMapSize represents the largest mmap size supported by Bolt.
6-
// Reduced for WASM due to memory constraints.
7-
const MaxMapSize = 0x10000000 // 256MB
6+
const MaxMapSize = 0x10000000
87

98
// MaxAllocSize is the size used when creating array pointers.
10-
// Slightly larger than MaxMapSize to accommodate metadata overhead.
11-
const MaxAllocSize = 0x10100000 // 257MB
12-
13-
func init() {
14-
// Override the default page size for WASM to use 4KB instead of 64KB.
15-
// This reduces memory usage and makes behavior more consistent with other platforms.
16-
// Note: Databases created with different page sizes are not compatible.
17-
DefaultPageSize = 4096
18-
}
19-
20-
// GetPagesize returns the system page size.
21-
// On WASM platforms, we always return 4KB as the page size.
22-
func GetPagesize() int {
23-
return 4096
24-
}
9+
const MaxAllocSize = 0x10100000

internal/common/pagesize.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)