Skip to content

Commit

Permalink
all: add website
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun committed Jan 21, 2021
1 parent a9be9a8 commit 31436e2
Show file tree
Hide file tree
Showing 44 changed files with 390 additions and 30 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: research
on:
push:
branches: [ master ]
jobs:

build:
name: research
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15
id: go

- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.60.1'
extended: true

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Build Research Website
env:
USER: ${{ secrets.SERVER_USER }}
TARGET: ${{ secrets.SERVER_PATH }}
KEY: ${{ secrets.SERVER_KEY }}
DOMAIN: ${{ secrets.SERVER_DOMAIN }}
run: |
make
mkdir ~/.ssh
echo "$KEY" | tr -d '\r' > ~/.ssh/idkey
chmod 400 ~/.ssh/idkey
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/idkey
ssh-keyscan -H $DOMAIN >> ~/.ssh/known_hosts
scp -r public/* $USER@$DOMAIN:$TARGET
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/
resources
public
.DS_Store
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
License
-------

Copyright (c) 2020 The golang.design Initiative
All Rights Reserved

Unauthorized using, copying, modifying and distributing, via any medium
is strictly prohibited.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
hugo
s:
hugo server
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# research

(Possibly) Naïve thoughts regarding Go.

## Table of Content
https://golang.design/research

- [Changkun Ou. Pointers Might Not Be Ideal for Parameters. Oct 27, 2020.](./pointer-params.md)
- [Changkun Ou. Eliminating A Source of Measurement Errors in Benchmarks. Sep 30, 2020.](./bench-time.md)
(Possibly) Naïve thoughts regarding Go.

## License

Expand Down
9 changes: 9 additions & 0 deletions archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
date: {{ now.Format "2006-01-02T15:04:05Z07:00" }}
toc: true
slug: /{{ .Name }}
tags:
- Go
title: {{ .Name }}
draft: true
---
39 changes: 39 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
baseURL = "https://golang.design/research"
languageCode = "en-us"
title = "golang.design/research"
theme = "research"
[permalinks]
posts = "/:slug"

[params]
subtitle = "(Possibly) Naïve thoughts regarding Go."
dateFmt = "02.01.2006"

[menu]
[[menu.main]]
identifier = "posts"
name = "Posts"
url = "/posts/"
weight = 1
[[menu.main]]
identifier = "tags"
name = "Tags"
url = "/tags/"
weight = 2
[[menu.footer]]
name = "GitHub"
url = "https://github.com/golang-design/research"
weight = 1
[markup]
[markup.highlight]
anchorLineNos = false
codeFences = true
guessSyntax = true
hl_Lines = ""
lineAnchors = ""
lineNoStart = 1
lineNos = true
lineNumbersInTable = false
noClasses = true
style = "native"
tabWidth = 4
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
31 changes: 17 additions & 14 deletions bench-time.md → content/posts/bench-time.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Eliminating A Source of Measurement Errors in Benchmarks
---
date: 2020-09-30T09:02:20+01:00
toc: true
slug: /bench-time
tags:
- Benchmark
- Error
- TimeMeasurement
title: Eliminating A Source of Measurement Errors in Benchmarks
---

Author(s): [Changkun Ou](https://changkun.de)

Last updated: 2020-09-30

## Introduction

About six months ago, I did a [presentation](https://golang.design/s/gobench)
that talks about how to conduct a reliable benchmark in Go.
Recently, I submitted an issue [#41641](https://golang.org/issue/41641) to the Go project, which is also a subtle issue that you might need to address in some cases.

<!--more-->

## Introduction

It is all about the following code snippet:

```go
Expand Down Expand Up @@ -141,7 +150,7 @@ go test -v -run=none -bench=WithTimer -benchtime=100000x -count=5 -cpuprofile cp

Sadly, the graph shows a chunk of useless information where most of the costs shows as `runtime.ReadMemStats`:

![pprof](./bench-time/pprof1.png)
![pprof](../assets/bench-time/pprof1.png)

This is because of the `StopTimer/StartTimer` implementation in the testing package calls `runtime.ReadMemStats`:

Expand Down Expand Up @@ -203,7 +212,7 @@ func (b *B) StopTimer() {

And re-run the test again, then we have:

![pprof](./bench-time/pprof2.png)
![pprof](../assets/bench-time/pprof2.png)

Have you noticed where the problem is? Yes, there is a heavy cost in calling `time.Now()` in a tight loop (not really surprising because it is a system call).

Expand Down Expand Up @@ -281,9 +290,7 @@ and you could see that the output remains end in the cost of `avg since: 16ns`.
Thus, in terms of benchmarking, the actual measured time of a target code equals
to the execution time of target code plus the overhead of calling `now()`:

<p align="center">
<img src="./bench-time/flow.png">
</p>
![](../assets/bench-time/flow.png)

Assume the target code consumes in `T` ns, and the overhead of `now()` is `t` ns.
Now, let's run the target code `N` times.
Expand Down Expand Up @@ -356,7 +363,3 @@ As a take-away message, if you would like to write a micro-benchmark (whose runs
- Changkun Ou. testing: inconsistent benchmark measurements when interrupts timer. Sep 26, 2020. https://golang.org/issue/41641
- Josh Bleecher Snyder. testing: consider calling ReadMemStats less during benchmarking. Jul 1, 2017. https://golang.org/issue/20875
- Beyer, D., Löwe, S. & Wendler, P. Reliable benchmarking: requirements and solutions. Int J Softw Tools Technol Transfer 21, 1–29 (2019). https://doi.org/10.1007/s10009-017-0469-y

## License

Copyright &copy; 2020 The [golang.design](https://golang.design) Authors.
28 changes: 17 additions & 11 deletions pointer-params.md → content/posts/pointer-params.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Pointers Might Not Be Ideal for Parameters
---
date: 2020-11-05T09:14:53+01:00
toc: true
slug: /pointer-params
tags:
- Performance
- Parameter
- Pointer
title: Pointers Might Not Be Ideal for Parameters
---

Author(s): [Changkun Ou](https://changkun.de)

Last updated: 2020-11-05

## Introduction

We are aware that using pointers for passing parameters can avoid data copy,
which will benefit the performance. Nevertheless, there are always some
edge cases we might need concern.

<!--more-->

## Introduction

Let's take this as an example:

```go
Expand Down Expand Up @@ -163,7 +173,7 @@ $ mkdir asm && go tool compile -S vec.go > asm/vec.s

The dumped assumbly code is as follows:

```asm
```
"".vec.addv STEXT nosplit size=89 args=0x60 locals=0x0 funcid=0x0
0x0000 00000 (vec.go:7) TEXT "".vec.addv(SB), NOSPLIT|ABIInternal, $0-96
0x0000 00000 (vec.go:7) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
Expand Down Expand Up @@ -392,7 +402,7 @@ Vec/addp-s9-16 3.37ns ± 0%
We could even further try a version that disables inline:

```diff
structTmpl = template.Must(template.New("ss").Parse(`
structTmpl = template.Must(template.New("ss").Parse(`
type {{.Name}} struct {
{{.Properties}}
}
Expand All @@ -412,7 +422,7 @@ func (s *{{.Name}}) addp(ss *{{.Name}}) *{{.Name}} {

Eventually, we will endup with the following results:

![](./pointer-params/vis.png)
![](../assets/pointer-params/vis.png)

TLDR: The above figure basically demonstrates when should you pass-by-value
or pass-by-pointer. If you are certain that your code won't produce any escape
Expand All @@ -427,7 +437,3 @@ then you should go for pass-by-value; otherwise, you should keep using pointers.
- MOVSD. Move or Merge Scalar Double-Precision Floating-Point Value. Last access: 2020-10-27. https://www.felixcloutier.com/x86/movsd
- ADDSD. Add Scalar Double-Precision Floating-Point Values. Last access: 2020-10-27. https://www.felixcloutier.com/x86/addsd
- MOVEQ. Move Quadword. Last access: 2020-10-27. https://www.felixcloutier.com/x86/movq

## License

Copyright &copy; 2020 The [golang.design](https://golang.design) Authors.
10 changes: 10 additions & 0 deletions themes/research/archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
date: {{ now.Format "2006-01-02T15:04:05Z07:00" }}
toc: true
id:
slug: /{{ .Name }}
tags:
- Go
title: {{ .Name }}
draft: true
---
11 changes: 11 additions & 0 deletions themes/research/layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ if .Title }}
<figure>
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
<figcaption>{{ .Title }}</figcaption>
</figure>
{{ else }}
<figure>
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
</figure>
{{ end }}

32 changes: 32 additions & 0 deletions themes/research/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode | default "en-us" }}">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-80889616-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-80889616-4');
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style type=text/css>body{font-family:monospace;}</style>
<title>{{ .Title }}</title>
{{ with .Site.Params.description }}<meta name="description" content="{{ . }}">{{ end }}
{{ with .Site.Params.author }}<meta name="author" content="{{ . }}">{{ end }}
<link rel="stylesheet" href="{{ "css/style.css" | relURL }}">
{{ range .Site.Params.customCSS -}}
<link rel="stylesheet" href="{{ . | relURL }}?rnd={{ now.Unix }}">
{{- end }}
{{ with .OutputFormats.Get "RSS" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s">` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }}
{{- end }}
</head>
<body>
{{ partial "header" . }}
{{ block "main" . }}{{ end }}
{{ partial "footer" . }}
</body>
</html>
26 changes: 26 additions & 0 deletions themes/research/layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{ define "main" }}
<main>
{{ $listtitle := .Title }}
{{ if or .Title .Content }}
<div>
{{ with .Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Content }}<div>{{ . }}</div>{{ end }}
</div>
{{ end }}

<ul>
{{ range .Paginator.Pages }}
<li>
<div class="post-title">
{{ if eq $listtitle "Posts" }}
{{ .Date.Format "2006-01-02" }} <a href="{{ .RelPermalink }}">{{.Title }}</a>
{{ else }}
<a href="{{ .RelPermalink }}">{{.Title }}</a>
{{ end }}
</div>
</li>
{{ end }}
</ul>
{{ partial "pagination.html" . }}
</main>
{{ end }}
15 changes: 15 additions & 0 deletions themes/research/layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ define "main" }}
<main>
<article>
<h1 class="title">{{ .Title }}</h1>
<b><time>{{ .Date.Format (default "2006-01-02 15:04:05" .Site.Params.dateFmt) }}</time></b>
{{ range .Params.tags }}
<a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">#{{ . }}</a>
{{ end }}
<div>
{{ .Content }}
</div>
</article>
</main>
{{ partial "sidebar.html" . }}
{{ end }}
13 changes: 13 additions & 0 deletions themes/research/layouts/_default/summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<article>
<h1><a class="title" href="{{ .Permalink }}">{{ .Title }}</a></h1>
<b><time>{{ .Date.Format (default "2006-01-02 15:04:05" .Site.Params.dateFmt) }}</time></b>
{{ range .Params.tags }}
<a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">#{{ . }}</a>
{{ end }}
<div>
{{ .Summary }}
{{ if .Truncated }}
<a href="{{ .Permalink }}">Read more...</a>
{{ end }}
</div>
</article>
9 changes: 9 additions & 0 deletions themes/research/layouts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ define "main" }}
<main>
{{ $paginator := .Paginate (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) }}
{{ range $paginator.Pages }}
{{ .Render "summary" }}
{{ end }}
{{ partial "pagination.html" . }}
</main>
{{ end }}
8 changes: 8 additions & 0 deletions themes/research/layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<footer>
<p>&copy; {{ now.Year }}
<a class="footer-link" href="https://golang.design"><b>The golang.design Initiative</b></a>.
{{- range .Site.Menus.footer }}
<a class="footer-link" href="{{ .URL }}"><b>{{ .Name }}</b></a>.
{{- end }}
</p>
</footer>
Loading

0 comments on commit 31436e2

Please sign in to comment.