Skip to content

DXE-4929 DCE and ozzo-validation #236

@ldez

Description

@ldez

Hello,

This library is currently using github.com/go-ozzo/ozzo-validation, but github.com/go-ozzo/ozzo-validation is using text/template to generate some error messages.

text/template is defeating the Dead Code Elimination (DCE) optimization (this is a known problem).

Simple example, with only one file:

package main

import (
	"fmt"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/v13/pkg/dns"
)

func main() {
	request := dns.CreateRecordRequest{}
	fmt.Println(request.Validate())
}

Compilation with github.com/go-ozzo/ozzo-validation:

$ go build -o sandbox .
$ ll sandbox 
Permissions Size User Group Date Modified  Name
.rwxr-xr-x   12M ldez ldez  21 avril 02:52 sandbox

$ go build -o sandbox -ldflags '-w -s' .
$ ll sandbox                            
Permissions Size User Group Date Modified  Name
.rwxr-xr-x  8,4M ldez ldez  21 avril 03:00 sandbox

Compilation with an altered version of github.com/go-ozzo/ozzo-validation without text/template:

$ go build -o sandbox .
$ ll sandbox           
Permissions Size User Group Date Modified  Name
.rwxr-xr-x  7,9M ldez ldez  21 avril 02:54 sandbox

$ go build -o sandbox -ldflags '-w -s' .
$ ll sandbox                            
Permissions Size User Group Date Modified  Name
.rwxr-xr-x  5,5M ldez ldez  21 avril 03:00 sandbox

As you can see, the size of the binary is decreased by ~40% when not using text/template.

It could be great if you can remove github.com/go-ozzo/ozzo-validation or use a fork without text/template.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions