Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Notorious b.s.d.
Jan 25, 2003

by Reene

Sweeper posted:

which malloc/free corner cases are you referring to? and while RAII isn't some magic bullet, it is a good concept. It allows for some great stuff like unique_ptr. There are many things wrong with c++, but RAII isn't one of em. I'm not sure what hairy profiling issues you are thinking of, but in my experience it makes it more obvious when you are allocating/deallocating memory. Perhaps someone doing stupid poo poo in destructors is causing you problems?

heap fragmentation sucks poo poo, even when the heap is handled by malloc/free and not a garbage collector

Sweeper posted:

If you need extremely low latency and high throughput (the niche that c++ lives in), I'd say there is a very small change you want to use a gc. It simply doesn't have the determinism you need to not have a pause at just the wrong time and kill your p100.

as with all other gc-related items, "it depends"

it is very much possible to control 99.9th percentile pause times. there are even garbage collectors with deterministic pause times. but it is a tradeoff against other behaviors, as listed in my prior post

and, of course, the actual time spent in malloc() and free() depends on total application behavior, not the size or behavior of the specific object or thread doing the allocation

it is not as simple as "i need determinism, ergo i need c++"

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015
Arenas are great, but surprisingly often you cannot get a non-trivial guarantee on the max alloc size.

tef
May 30, 2004

-> some l-system crap ->
time to recycle views on garbage collection

pseudorandom name
May 6, 2007

Cybernetic Vermin posted:

while that stuff will usually just be done on a gc thread along with other things it will be outside the "stop the world" phase of the gc, so it is usually not a noticeable problem in any way

just getting the things done in one go is good for throughput as well, avoid repeatedly having to basically trash the applications cache state by walking about random dead objects (same issue as with refcounting, which will often in practice turn out extremely expensive since it inserts a lot of pokes at memory which is not in cache and not otherwise useful to have in cache). it may seem like there is no gain in that the gc also wont have the dead objects in cache when it finishes the scan to determine they are dead, but at that point the cache contains mostly junk anyway (i.e. the final bits of the tracing) so it is no loss evicting it

if the thinking is to defer cleaning up objects for a long time to get a huge amount of work done: why not defer the entire gc if you have that kind of memory to spare?

I'm specifically asking about running destructors and freeing memory off the main thread in a non-GC scenario.

Notorious b.s.d.
Jan 25, 2003

by Reene

tef posted:

time to recycle views on garbage collection

the nursery always needs a thorough reaping

raminasi
Jan 25, 2005

a last drink with no ice

redleader posted:

don't be loving stupid. how dare you even think of having more than one memory management paradigm in a language

thanks for the reminder that c++/cli exists

feedmegin
Jul 30, 2008

pseudorandom name posted:

I'm specifically asking about running destructors and freeing memory off the main thread in a non-GC scenario.

I could see issues with running non-trivial destructors on some random rear end thread other than the one it was created in tbh

pseudorandom name
May 6, 2007

feedmegin posted:

I could see issues with running non-trivial destructors on some random rear end thread other than the one it was created in tbh

Oh, yeah, if you're e.g. using RAII for lock release this would be a disaster, but I'm curious if anybody has every tried it in experimental languages or whatever.

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

tef posted:

time to recycle views on garbage collection

better than talking build systems and producing a byte-for-byte identical conversation

Nomnom Cookie
Aug 30, 2009



pseudorandom name posted:

I'm specifically asking about running destructors and freeing memory off the main thread in a non-GC scenario.

you have pools and arenas available, for one thing. also I'm not sure that a thread-safe enqueue is going to be cheaper than free(). atomics are expensive

luchadornado
Oct 7, 2004

A boombox is not a toy!

Kevin Mitnick P.E. posted:

also I'm not sure that a thread-safe enqueue is going to be cheaper than free().

theres a reason the disruptor pattern exists and happens to be fast as poo poo

tef
May 30, 2004

-> some l-system crap ->
it's a ring buffer and doesn't use allocation woop

Nomnom Cookie
Aug 30, 2009



Helicity posted:

theres a reason the disruptor pattern exists and happens to be fast as poo poo

atomics are still expensive and i'd be somewhat surprised if modern mallocs used any on the fast path

luchadornado
Oct 7, 2004

A boombox is not a toy!

i was essentially agreeing with your statement about enqueue

if you dont run into queues and locks being a bottleneck, its probably not that interesting of a pattern i suppose

Nomnom Cookie
Aug 30, 2009



ah

tef
May 30, 2004

-> some l-system crap ->

pseudorandom name posted:

I'm specifically asking about running destructors and freeing memory off the main thread in a non-GC scenario.

i mean, theoretically, this is a great idea, because items that are dead won't have any existing references, except of course if your finalizer creates zombies

anyway, here's the thing

- rust has garbage collection, it has managed memory, it just doesn't do tracing,

- gc has come forward in leaps and bounds since 1996

- rust has opt in dynamic ref counting (& atomic variants) already and people have been working on #[derive(Trace)] like stuff since forever

- but yeah, reference counting adds about 10-20% to the runtime costs of a program

- you need to end up doing things like bump/line allocators, deferred reference counting, and other fancy pants poo poo

- and the other problem is that you need to do incremental deallocation, or you get long pauses in your application

it turns out writing performant code isn't made easier by avoiding the gc who knew

Doom Mathematic
Sep 2, 2008

prisoner of waffles posted:

better than talking build systems and producing a byte-for-byte identical conversation

Nomnom Cookie
Aug 30, 2009



tef posted:

i mean, theoretically, this is a great idea, because items that are dead won't have any existing references, except of course if your finalizer creates zombies

anyway, here's the thing

- rust has garbage collection, it has managed memory, it just doesn't do tracing,

- gc has come forward in leaps and bounds since 1996

- rust has opt in dynamic ref counting (& atomic variants) already and people have been working on #[derive(Trace)] like stuff since forever

- but yeah, reference counting adds about 10-20% to the runtime costs of a program

- you need to end up doing things like bump/line allocators, deferred reference counting, and other fancy pants poo poo

- and the other problem is that you need to do incremental deallocation, or you get long pauses in your application

it turns out writing performant code isn't made easier by avoiding the gc who knew

I really really hope you’re not saying that not needing to call free is the same as GC

tef
May 30, 2004

-> some l-system crap ->

Kevin Mitnick P.E. posted:

I really really hope you’re not saying that not needing to call free is the same as GC

quack

redleader
Aug 18, 2005

Engage according to operational parameters
gonna get some cutting edge cs research going in the yospos smart programmers thread

tef
May 30, 2004

-> some l-system crap ->
rust literally does one bit ref counting (the drop flag), and uses compile time checks to enforce the count never exceeds 1

ref counting and tracing are duals, to the point where any _serious_ gc in the last ten-twenty years has some overlap

https://www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf

i mean, from a coarse view point: reference counting scans dead objects (to deallocate), tracing scans live ones

and there's literally no issue in combining both

https://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon01Concurrent.pdf

but yeah i'm saying, weirdly enough, reference counting is a form of garbage collection

tef
May 30, 2004

-> some l-system crap ->

redleader posted:

gonna get some cutting edge cs research going in the yospos smart programmers thread

http://users.cecs.anu.edu.au/~steveb/pubs/papers/rcix-oopsla-2013.pdf

here's a slightly less old paper

tef
May 30, 2004

-> some l-system crap ->
it's the one about 'so how can we get reference counting to within the performance of gc'

Nomnom Cookie
Aug 30, 2009



tef posted:

rust literally does one bit ref counting (the drop flag), and uses compile time checks to enforce the count never exceeds 1

ref counting and tracing are duals, to the point where any _serious_ gc in the last ten-twenty years has some overlap

https://www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf

i mean, from a coarse view point: reference counting scans dead objects (to deallocate), tracing scans live ones

and there's literally no issue in combining both

https://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon01Concurrent.pdf

but yeah i'm saying, weirdly enough, reference counting is a form of garbage collection

I don’t believe it’s useful to redefine GC as “don’t need to call free” but I am too tired to call you names over it

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

raminasi posted:

thanks for the reminder that c++/cli exists

does this compile to the CLR bytecode (or whatever it's called) that "regular" languages like c# compile to? or can you do wacky mix and match stuff with both CLR and traditional machine code

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



tef posted:

time to recycle views on garbage collection

prisoner of waffles posted:

better than talking build systems and producing a byte-for-byte identical conversation

lol

Dylan16807
May 12, 2010

Kevin Mitnick P.E. posted:

you have pools and arenas available, for one thing. also I'm not sure that a thread-safe enqueue is going to be cheaper than free(). atomics are expensive

the starter question was about doing large deallocations on a thread, so compare more an enqueue to save 30+ of them, or whatever number you like

Dylan16807 fucked around with this message at 08:26 on Oct 21, 2018

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

tef posted:

but yeah i'm saying, weirdly enough, reference counting is a form of garbage collection

I sincerely hope that anyone who cares about the meanings of the terms understands this

like, the folks who created OpenStep’s autorelease pool mechanism, and then autozone, and then ARC for ObjC and then Swift certainly did

animist
Aug 28, 2018
you ever wish we all could just confine ourselves to finite state machines and forget about memory forever

Cybernetic Vermin
Apr 18, 2005

ultimately all machines are finite state

animist
Aug 28, 2018
technically all machines are made of analog components following the digital discipline so they're not really finite state unless the universe is discretized send tweet

Zlodo
Nov 25, 2006
the problem with garbage collectors is that they are usually black boxes because they are designed around a "don't worry about memory, we'll take care of it" philosophy

reference counting, on the other hand (I know it's also a garbage collector, bear with me) while not a magic bullet, is easier to understand and performance issues are easier to troubleshoot and work around

I have a friend who works at a company where they build test benches and the software is VB .net, when they deal with massive amounts of real time data acquisition they can often run into latency issues caused by the garbage collector because it waits too long to collect things and then do it all at once

he told me stories of debugging this kind of things that are a hundred times scarier than anything I ever experienced with c++

of course malloc/free is also a mysterious black box but I think tracing garbage collectors are much worse

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



ya we had huge problems with GC when running reports at a previous job

hundreds of thousands of object trees per week being boiled down to lineitem objects that were eventually serialized in multiple files & formats

running the quarterlies took like 10+ hrs and from what I remember of the logs, I wanna say like half was just gc

feedmegin
Jul 30, 2008

Lutha Mahtin posted:

does this compile to the CLR bytecode (or whatever it's called) that "regular" languages like c# compile to? or can you do wacky mix and match stuff with both CLR and traditional machine code

The latter.

Cybernetic Vermin
Apr 18, 2005

while not suitable in every setting i always react to complaints about the latency of gc by suspecting that the programmers who are having the issues would have plenty of issues in any other settings as well. some things are realtime sensitive, but having done stock exchanges in java, often replacing one done in c/c++ while offering far better latency, i don't expect that many of those hard cases come up

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



no doubt the code was awful in many ways but the gc caused the most trouble

luchadornado
Oct 7, 2004

A boombox is not a toy!

i see a decent number of devs solve network/cpu/thread bottlenecks with many-thousands-of-rps-apis and then come to memory issues and get totally flummoxed because that magical black box isnt working exactly the way they want it any longer and theyve never had to worry about being memory efficient because 32gb ram is dirt cheap

tef
May 30, 2004

-> some l-system crap ->
what if it's programmers blaming the one thng they don't understand & can't control meaningfully

like these are the sort of people who put while loops in critical sections

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Zlodo posted:

the problem with garbage collectors is that they are usually black boxes because they are designed around a "don't worry about memory, we'll take care of it" philosophy

how do you feel about your processor's cache

Adbot
ADBOT LOVES YOU

akadajet
Sep 14, 2003

Internet Janitor posted:

how do you feel about your processor's cache

it's great until it leaks secrets

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply