Skip to content

Pre-Process Structs instead of on-the-fly #206

@CodeShellDev

Description

@CodeShellDev

Description

Currently almost all mixed lists, like []string with action=block|allow or custom structs like field policies (ex.: endpoints, ipfilters, fieldpolicies) are parsed on-the-fly, this means that for example endpoints have to be split based on prefix ! into allowed and blocked.
This can be a bit expensive and often is unnecessary, since it doesn't change (apart from config reloads) this could greatly improve performance!

Solution

CUSTOM PARSERS. (well actually these are just transforms again)

This means probably some implementation of this:

type ACCESS struct {
	ENDPOINTS Endpoint	`koanf:"endpoints" parser:"allowed-blocked-parser"`
}

type Endpoint struct {
	Allowed []string
	Blocked []string
}

func allowedBlockedParser(key string, value any) (string, any) {
	if strings.HasPrefix(value.(string), "!") {
		return key + ".allowed", value
	}
	return key + ".blocked", value
}

But we already have transform:"func-name"
Why can't we use that?

Well, this is because transforms only take into account a section of the key like url instead of say api.url,
in my head it is just adding another parameter for the fullkey and done, but I know I would hit some kind of wall again.

Alternatives

Ignore the performance loss

Metadata

Metadata

Assignees

No one assigned

    Labels

    choreSomething doesn't envolve new features and instead focuses on the devex and codebaseenhancementNew feature or requestneeds testingSomething needs testingpriority/lowSomething is of low priorityscale/largeThis is a large change

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions