Functional Game Programming Suggestions

120 views
Skip to first unread message

jmilton

unread,
Jan 5, 2013, 1:54:24 PM1/5/13
to pragmatic-functional...@googlegroups.com
I am exploring the idea of developing a 3d game with a functional programming language, such as Ocaml or F#. I'd rather not choose Haskell, since virtually of the game examples using functional programming use Haskell.

Garbage collection will inevitably lead to performance problems. Without depending so much on FFI's to libraries written in C or C++, what are some ways I can minimize this inevitable performance issue?

Malcolm Matalka

unread,
Jan 5, 2013, 1:59:38 PM1/5/13
to jmilton, pragmatic-functional...@googlegroups.com

One way is to avoid causing gc's but not allocating or freeing data. This is basically what games do in unmanaged languages anyways.

On Jan 5, 2013 7:54 PM, "jmilton" <intlres...@sent.com> wrote:
I am exploring the idea of developing a 3d game with a functional programming language, such as Ocaml or F#. I'd rather not choose Haskell, since virtually of the game examples using functional programming use Haskell.

Garbage collection will inevitably lead to performance problems. Without depending so much on FFI's to libraries written in C or C++, what are some ways I can minimize this inevitable performance issue?

--
 
 

jmilton

unread,
Jan 5, 2013, 2:12:34 PM1/5/13
to pragmatic-functional...@googlegroups.com, jmilton
I figured as much. Are you familiar with practices in Ocaml and F# that can achieve this GC avoidance? Have you found Ocaml and F# arrays and hashtables suitable for this?

Malcolm Matalka

unread,
Jan 5, 2013, 2:18:01 PM1/5/13
to jmilton, pragmatic-functional...@googlegroups.com

Jon definitely has more experience than I so I will defer to him. I suspect arrays will play an important part of any solution. 

--
 
 

Jon Harrop

unread,
Jan 6, 2013, 7:46:11 PM1/6/13
to jmilton, pragmatic-functional...@googlegroups.com

Premature optimization. I doubt you’ll have problems with latency. I had problems with latency when I was developing a 114us latency fault tolerant server in F# but a game won’t require anything like that kind of performance.

 

OCaml’s GC pauses are typically 10ms. .NET’s workstation GC pauses (last I looked) were typically 30ms. But .NET’s GCs get more concurrent with each release…

 

FWIW, Haskell (GHC) has a stop-the-world GC.

 

Cheers,

Jon.

 

--
 
 

Jon Harrop

unread,
Jan 6, 2013, 7:46:41 PM1/6/13
to Malcolm Matalka, jmilton, pragmatic-functional...@googlegroups.com

You can do that in .NET thanks to value types but not OCaml.

 

--
 
 

Jon Harrop

unread,
Jan 6, 2013, 7:47:48 PM1/6/13
to jmilton, pragmatic-functional...@googlegroups.com

Bad idea for OCaml. The existence of arrays (including the spine of a hash table) in the heap causes OCaml’s GC to pause. You want to do the exact opposite in OCaml: use purely functional data structures because they are fragmented and much more amenable to low-latency GC. You could also shrink the size of the nursery if you really need to (which you won’t!).

 

From: pragmatic-functional...@googlegroups.com [mailto:pragmatic-functional...@googlegroups.com] On Behalf Of jmilton
Sent: 05 January 2013 19:13
To: pragmatic-functional...@googlegroups.com
Cc: jmilton
Subject: Re: Functional Game Programming Suggestions

 

I figured as much. Are you familiar with practices in Ocaml and F# that can achieve this GC avoidance? Have you found Ocaml and F# arrays and hashtables suitable for this?

--
 
 

jmilton

unread,
Jan 18, 2013, 10:47:54 AM1/18/13
to pragmatic-functional...@googlegroups.com, jonathand...@googlemail.com
Thanks,

I think I will use a simple functional scene graph using variant types.  F# seems to be the better option because of value type support and better interop. with cross platform libraries such as OpenTK, except that under Linux, F# performance was still lagging the last time I checked.
Reply all
Reply to author
Forward
0 new messages