t1 | t2 |
---|---|
Set A=1 | |
Set A=2 | |
Set B=2 | |
Set B=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
func main() { | |
// Init | |
n := 1_000_000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1 | t2 | |
---|---|---|
Read InventorySize (100) | ||
Read InventorySize (100) | ||
Set InventorySize to 100 + 5 = 105 | ||
Set InventorySize to 100 + 10 = 110 | ||
Commit | ||
Commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1 | t2 | |
---|---|---|
Read A | ||
Set A=1 | ||
Commit | ||
... | ||
Read A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1 | t2 | |
---|---|---|
Set A=0 | ||
Delete rows where A=0 | ||
Rollback | ||
Commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1 | t2 | |
---|---|---|
Set A=1 | ||
Set A=2 | ||
Set B=2 | ||
Set B=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func concat(values []string) string { | |
total := 0 | |
for i := 0; i < len(values); i++ { | |
total += len(values[i]) | |
} | |
sb := strings.Builder{} | |
sb.Grow(total) | |
for _, value := range values { | |
_, _ = sb.WriteString(value) |
Step | map[int][128]byte |
map[int]*[128]byte |
---|---|---|
Allocate an empty map | 0 MB | 0 MB |
Add 1 million elements | 461 MB | 182 MB |
Remove all the elements and run a GC | 293 MB | 38 MB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type hmap struct { | |
B uint8 // log_2 of # of buckets | |
// (can hold up to loadFactor * 2^B items) | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
n := 1_000_000 | |
m := make(map[int][128]byte) | |
printAlloc() | |
for i := 0; i < n; i++ { // Adds 1 million elements | |
m[i] = [128]byte{} | |
} | |
printAlloc() |