Skip to content

Global static keyword proposal #12

@john-bv

Description

@john-bv

Similar to class implementation, you should be able to store variables on STACK rather than HEAP with the static keyword.

Please note that the implementation of static on a class property or method is different from global statics. Method and properties of classes will remain on HEAP.

Example implementation:

import * from std.http;
import JSON from std;

static api_endpoint: string = "https://myapi.com/api/"; // will never change and collected from stack
const version: Future<JSON> = await fetch(api_endpoint);
print("API Version: " + version);

It is important to note, if you do not declare a static global as public it is disposed after it is owned. (this can be disabled with compiler flags)

Why? Allocating known strings or any related interface on heap is more time consuming than allocating on stack. Allocating on stack allows us to shorten instruction size into a single instruction, as well as allowing better lifetime control of the variable.

Please note this RFC will not be as efficient without lifetimes enabled

Metadata

Metadata

Assignees

Labels

FeatureThis issue or PR contains a new feature.FutureThis issue or PR is something that will be added in the future.High PriorityHigh profile, important issue that needs to be focused on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions