Antti Haapala added the comment:

Serhiy suggested this in Rietveld:

> For additional optimization we can pack all constant strings, parsed formats 
> and
> flags in one constant object and use the single LOAD_CONST. But this requires
> much larger changes (perhaps including changing the marshal format), and the
> benefit may be small. Maybe we'll get to it eventually, if this approach 
> proves
> efficient enough.

I was thinking about this and got an idea on how to do this too, without 
changes to marshal. Essentially, let TOS be a tuple of 

    (flags, str1, str2, str3, str4, str5, str6, str7, str8, str9...)

flags would be n bytes for n-part format string; each byte would tell whether:

- the next component is a constant string (bit 0 = 0) from the tuple
- the next component is an interpolated value (bit 0 = 1)
   - and whether it has !s, !r, !a or default conversions (bits 1-2)
   - and whether it has extra argument to format() or not (bit 3) (argument is 
the next string from the tuple)

thus that tuple for

    a, b = 'Hello', 'World!'
    f'{a!s} {b:10}!'

would be

    (b'\x03\x00\x05\x00', ' ', '10', '!')

and the opcodes would be

    LOAD_FAST (b)
    LOAD_FAST (a)
    LOAD_CONST (0) (the tuple)
    BUILD_FORMAT_STRING 3

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27078>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to