unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* a C<->guile O(2N) problem
@ 2019-12-08 13:15 Christopher Lam
  2019-12-11 14:47 ` Christopher Lam
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher Lam @ 2019-12-08 13:15 UTC (permalink / raw)
  To: guile-user

Hello guilers

I am asking for some help optimizing C<->guile while working on the
simplest of lispy data structures; the proper list. The C equivalent being
used is glib's g_list.

In https://github.com/Gnucash/gnucash/blob/maint/common/base-typemaps.i#L142
these are converted via the simple but O(2*N) expensive
prepend-and-reverse, building SCM list by traversing g_list, and vice versa
for the return trip.

It came to light that if we could define the GList transform with CAR =
node->data and CDR = node->next; the C->SCM transform could be O(1)
efficient. There are issues about finding the correct SWIG converter for
node->data pointer dereferences, but this is a problem for another day.
With SCM->C transform, we don't anticipate long lists, so, the issue is
less acute, but it would be nice to optimise it too.

Does anyone have experience converting the above efficiently? Is this
something that would need ffi work?

Thanks for any help!


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: a C<->guile O(2N) problem
  2019-12-08 13:15 a C<->guile O(2N) problem Christopher Lam
@ 2019-12-11 14:47 ` Christopher Lam
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Lam @ 2019-12-11 14:47 UTC (permalink / raw)
  To: guile-user

Update: the solution turned out to be easy to do in swig, and actually not
that useful. Prepend-and-reverse to convert g_list to SCM list, for lists
tested up to 10e6, takes a fraction of a second.

https://github.com/Gnucash/gnucash/pull/620 was the proof-of-concept O(1)
GList->SplitListNode with benchmarks.


On Sun, 8 Dec 2019 at 13:15, Christopher Lam <christopher.lck@gmail.com>
wrote:

> Hello guilers
>
> I am asking for some help optimizing C<->guile while working on the
> simplest of lispy data structures; the proper list. The C equivalent being
> used is glib's g_list.
>
> In
> https://github.com/Gnucash/gnucash/blob/maint/common/base-typemaps.i#L142
> these are converted via the simple but O(2*N) expensive
> prepend-and-reverse, building SCM list by traversing g_list, and vice versa
> for the return trip.
>
> It came to light that if we could define the GList transform with CAR =
> node->data and CDR = node->next; the C->SCM transform could be O(1)
> efficient. There are issues about finding the correct SWIG converter for
> node->data pointer dereferences, but this is a problem for another day.
> With SCM->C transform, we don't anticipate long lists, so, the issue is
> less acute, but it would be nice to optimise it too.
>
> Does anyone have experience converting the above efficiently? Is this
> something that would need ffi work?
>
> Thanks for any help!
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-11 14:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-08 13:15 a C<->guile O(2N) problem Christopher Lam
2019-12-11 14:47 ` Christopher Lam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).