Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V allocates too much memory #20276

Open
MCausc78 opened this issue Dec 26, 2023 · 0 comments
Open

V allocates too much memory #20276

MCausc78 opened this issue Dec 26, 2023 · 0 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@MCausc78
Copy link
Contributor

MCausc78 commented Dec 26, 2023

Describe the bug

<title>

Reproduction Steps

pub interface Component {
	is_component()
}

pub struct ActionRow {
pub:
	components []Component
}

fn (_ ActionRow) is_component() {}

pub fn (ar ActionRow) walk[T](f fn (T) bool) ?T {
    for c in ar.components {
        if c is T {
            if f(c) {
                return c
            }
        } else if c is ActionRow {
            if d := c.walk(f) {
                return d
            }
        }
    }
    return none
}

pub struct TextInput {
pub:
	custom_id string @[required]
	value ?string
}

fn (_ TextInput) is_component() {}

fn main() {
	ar := ActionRow{
		components: [
			TextInput{
				custom_id: 'foo'
				value: 'bar'
			}
		]
	}
	if d := ar.walk(fn (ti TextInput) bool {
		return ti.custom_id == 'foo'
	}) {
		println('value: ${d.value}')
	} else {
		eprintln('not found')
	}
}

Expected Behavior

Successful compile, without eating 1 gb

Current Behavior

I see in Process Manager that v.exe eats >32 GB of RAM (i have 64 GB of RAM)

In V playground:

Running code...
Can't run code. The server returned an error:
V panic: malloc_noscan(627) failed
v hash: cd337e2
C.backtrace returned less than 2 frames
Exited with error status 1
Please try again.

Possible Solution

Limit count of allocations

Additional Information/Context

When compiling my discord.v project, V eated 40 GB of RAM

V version

V 0.4.3 57a33c3

Environment details (OS name and version, etc.)

V full version: V 0.4.3 57a33c3
OS: windows, Microsoft Windows 11 Pro v22000 64-bit
Processor: 12 cpus, 64bit, little endian,

getwd: C:\Users\mclr
vexe: D:\Games\Proekti\V\v\v.exe
vexe mtime: 2023-12-26 12:58:16

vroot: OK, value: D:\Games\Proekti\V\v
VMODULES: OK, value: C:\Users\mclr\.vmodules
VTMP: OK, value: C:\Users\mclr\AppData\Local\Temp\v_0

Git version: git version 2.37.0.windows.1
Git vroot status: weekly.2023.52-1-g57a33c31
.git/config present: true

CC version:
thirdparty/tcc status: thirdparty-windows-amd64 a39eb79b

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@MCausc78 MCausc78 added the Bug This tag is applied to issues which reports bugs. label Dec 26, 2023
@spytheman spytheman added Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Dec 26, 2023
@spytheman spytheman self-assigned this Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

2 participants