Skip to content

Inefficient code generated for large arrays initialization. #1007

@nevkontakte

Description

@nevkontakte

This issue is related to golang/go#34395 and https://github.com/golang/go/blob/master/test/fixedbugs/issue34395.go.

For a declaration like this:

var test = [100 * 1024 * 1024]byte{42}

GopherJS will attempt to generate code like this:

		test = $toNativeArray($kindUint8, [42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ... more zeros here */, 0, 0, 0, 0]);

For excessively large arrays the compiler will simply run out of memory and crash. For smaller arrays it may be able to generate the code, but the output would be unnecessarily large. It will be much more efficient (both in output and runtime performance) to pass non-zero elements and the length, and let the runtime handle zeros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions