xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Perl use SV treating all types, IV, NV, SV, IO etc, and can switch type as any time. Most of time, it’s a very handy mechanism, neither type error nor need type cast. But when performance of program is a point, this will become irresistible.

Someone would say why not XS? Yes, XS is powerful, but it’s not silver bullet, especially, perl still consume amount of time to inbox and outbox value (perl at least use 4 words to store a int). for example, I’d like to read some strings from a CSV, then search in a DB by these strings, at last write the string retrieved from DB into a new file. In order to speed it up, I use XS module as much as possible. I use TEXT::CSV_XS for reading/wrting file, use DBI for read DB, frustratingly, the program in perl is still slow.

Why? Since perl convert strings in file to SV, then convert SV to string for Database, then convert strings read from DB to SV, at last, convert SV to string for write file. When I’ve learned perl internal recently, one idea is getting into my mind repeatedly. Why wouldn't add native type in to perl? not refcount, no magic, can't change type, and only in lexical. The native value only live in declearing lexical. Like: { my native str $bb = “ hello world”; # cstring; my $cc = “hello world”; #perl string } In this way, when doing the jobs to communicate external library/program like above, perl is more like transparent bridge and no any extra performance loss.

It’s just a thought when I read perlguts, Is it a good idea or not? Please monks enlighten me. TIA.