Skip to content

Performance work#740

Draft
madig wants to merge 1 commit intomainfrom
performance-work
Draft

Performance work#740
madig wants to merge 1 commit intomainfrom
performance-work

Conversation

@madig
Copy link
Copy Markdown
Collaborator

@madig madig commented Oct 27, 2021

See #733.

Comment thread Lib/glyphsLib/classes.py Outdated
@madig
Copy link
Copy Markdown
Collaborator Author

madig commented Oct 27, 2021

I was going to rewrite the parse_float_or_int function like so:

def parse_float_or_int(value_string):
    # NOTE: Profile any changes you make to this function, as it is in the hot
    # file loading path. E.g.
    #
    #   In [32]: %timeit parse_float_or_int("2000")
    #       ...: %timeit parse_float_or_int("-2000")
    #       ...: %timeit parse_float_or_int("123.456")
    #       ...: %timeit parse_float_or_int("-123.456")
    #   183 ns ± 1.11 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #   186 ns ± 0.614 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #   199 ns ± 2.69 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #   201 ns ± 1.56 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #
    # There's another way of writing it:
    #
    #   In [2]: def parse_float_or_int2(value_string):
    #      ...:     try:
    #      ...:         return int(value_string)
    #      ...:     except ValueError:
    #      ...:         return float(value_string)
    #
    # The usual case of integers parses slighly faster, but as of Python 3.9.7, the
    # exceptional case of floating point coordinates is much slower.
    #
    #     In [36]: %timeit parse_float_or_int2("2000")
    #         ...: %timeit parse_float_or_int2("-2000")
    #         ...: %timeit parse_float_or_int2("123.456")
    #         ...: %timeit parse_float_or_int2("-123.456")
    #       170 ns ± 1.46 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #       173 ns ± 2.41 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #       1.18 µs ± 10.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #       1.19 µs ± 7.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #
    if "." in value_string:
        return float(value_string)
    return int(value_string)

but apparently it is not necessarily called with a string but also floats and ints in various places?????

Another stumbling block is the function behavior, for "100.0" it will return int(100); changing this makes some equivalence tests fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants