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

Inline popular functions #294

Closed
wants to merge 7 commits into from

Conversation

@Komzpa
Copy link
Member

commented Sep 12, 2018

Inline various popular functions similar to #290.

@pramsey

This comment has been minimized.

Copy link
Member

commented Sep 12, 2018

Not that it matters a lot, but what is the downside? How much bigger are the binaries, etc?

*
**********************************************************************
*
* Copyright 2018 Darafei Praliaskouski <me@komzpa.net>

This comment has been minimized.

Copy link
@dbaston

dbaston Sep 12, 2018

Member

This is all copy-pasted from somewhere else; copyright should follow.

This comment has been minimized.

Copy link
@Komzpa

Komzpa Sep 12, 2018

Author Member

fixed

if (dst_p1 > dst_p2)
{

This comment has been minimized.

Copy link
@dbaston

dbaston Sep 12, 2018

Member

Are these changes related to the inlining?

This comment has been minimized.

Copy link
@Komzpa

Komzpa Sep 12, 2018

Author Member

yes, they remove a call to fmax/fmin.

@dbaston

This comment has been minimized.

Copy link
Member

commented Sep 12, 2018

Seems reasonable in concept, but I'd be curious to know the performance difference in an actual query.

@Komzpa

This comment has been minimized.

Copy link
Member Author

commented Sep 12, 2018

On -O3 -march=native -g and gcc 7.3.0:

inlined:
-rwxrwxr-x 1 kom kom 3774184 вер 12 03:05 liblwgeom/.libs/liblwgeom-3.0.so.0.0.0*
stripped inlined:
-rwxrwxr-x 1 kom kom 825272 вер 12 03:40 liblwgeom/.libs/liblwgeom-3.0.so.0.0.0*

svn-trunk:
-rwxrwxr-x 1 kom kom 2719280 вер 12 03:37 liblwgeom/.libs/liblwgeom-3.0.so.0.0.0*
stripped svn-trunk:
-rwxrwxr-x 1 kom kom 641080 вер 12 03:38 liblwgeom/.libs/liblwgeom-3.0.so.0.0.0*

+180kb executable, +800kb debug symbols.

Speeds, inlined:

04:03:02 [postgis_reg] > select '#3971', count(*) 
[more] - > from (
[more] ( >          with
[more] ( >                  points as (
[more] ( >                  select ST_MakePoint(x, y) geom
[more] ( >                  from generate_series(1, 450) x, generate_series(1, 450) y
[more] ( >              )
[more] ( >          select
[more] ( >              ST_ClusterKMeans(geom, 81)
[more] ( >              over () as cid,
[more] ( >              geom
[more] ( >          from points
[more] ( >      ) z
[more] - > group by cid
[more] - > order by count(*)
[more] - > limit 1;
┌──────────┬───────┐
│ ?column? │ count │
├──────────┼───────┤
│ #3971    │  2077 │
└──────────┴───────┘
(1 row)

Time: 3468,420 ms (00:03,468)

2.5:

04:04:07 [kom] > select '#3971', count(*) 
[more] - > from (
[more] ( >          with
[more] ( >                  points as (
[more] ( >                  select ST_MakePoint(x, y) geom
[more] ( >                  from generate_series(1, 450) x, generate_series(1, 450) y
[more] ( >              )
[more] ( >          select
[more] ( >              ST_ClusterKMeans(geom, 81)
[more] ( >              over () as cid,
[more] ( >              geom
[more] ( >          from points
[more] ( >      ) z
[more] - > group by cid
[more] - > order by count(*)
[more] - > limit 1;
┌──────────┬───────┐
│ ?column? │ count │
├──────────┼───────┤
│ #3971    │  2077 │
└──────────┴───────┘
(1 row)

Time: 5942,388 ms (00:05,942)
@dbaston

This comment has been minimized.

Copy link
Member

commented Sep 12, 2018

Impressive!

@strk strk closed this in 4ca5e0e Sep 12, 2018

@@ -58,6 +58,9 @@ dnl
PICFLAGS="$lt_prog_compiler_pic"
AC_SUBST([PICFLAGS])

AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-math-errno], [_cv_nomatherrno], [-fno-math-errno], [], [CFLAGS="$CFLAGS -fno-math-errno"], [])

This comment has been minimized.

Copy link
@dbaston

dbaston Sep 12, 2018

Member

Do these flags provide significant performance gain? I get some discomfort from venturing outside of IEEE floating point.

This comment has been minimized.

Copy link
@Komzpa

Komzpa Sep 12, 2018

Author Member

It inlines all sqrt calls. It's safe - it just doesn't try to keep errno for floating point operations, which we don't use anyway. We for some reason import errno.h all over, but never use - cleanup is in #295

@Komzpa Komzpa deleted the Komzpa:inline_popular_methods branch Sep 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.