Comments (13)
First, about the discrepancy: it turns out there's a performance bug lurking here. For an object with attributes, we would generate a BUILDALL
. When the object had no attributes, we should have generated an empty, shared, one, but due to a bug did not do so. I've fixed that now.
The dynamic optimizer is getting increasingly sophisticated, and benchmarks like these are liable to prove little. Having fixed the BUILDALL
production bug above, it turns out that:
class Foo { }; for 1..10000000 { Foo.new }
Has the object allocation optimized out completely thanks to escape analysis and resultant optimizations, meaning after optimization it turns into an empty loop body. It's not yet sophisticated enough to do the same trick for an object with an attribute that is initialized but then never read, but that's only a matter of time; it already knows that floor_n
is pure if unused, so once the escape analyzer is smart enough, that'll turn into another benchmark proving nothing. :-)
As to the WHEN
feature, I think that belongs in module space; getting the current timestamp is certainly not free, and storing it is not in the slightest bit free either. Imagine an array with a million elements; that's 8 megabytes worth of storage on timestamps for all of the elements, and it's difficult to optimize such things out. With ordinary lexicals it's easier, but that's also the case where it has the least storage cost. So it's not just a time issue (though that is an issue), but also a memory one.
All the same, I'm glad you opened the issue, because it led to a performance bug being fixed.
@AlexDaniel I can look into cleaning up and publishing such a document, but I'm not immediately sure where to put it; any suggestions?
from problem-solving.
$ time perl6 -e 'class Foo { }; for 1..1000000 { Foo.new }'
real 0m0.585s
user 0m0.629s
sys 0m0.051s
$ time perl6 -e 'class Foo { has $.WHEN = now; }; for 1..1000000 { Foo.new }'
real 1m12.477s
user 1m8.057s
sys 0m4.085s
This is a bit of a naive example, but the performance implications are pronounced enough to make me think its impractical.
from problem-solving.
What about creating a module “WHEN::Hash” for those who need it instead of imposing the overhead on everyone?
BTW, @jnthn can you publish your document about language design principles?
from problem-solving.
$ time perl6 -e 'class Foo { }; for 1..1000000 { Foo.new }' real 0m0.585s user 0m0.629s sys 0m0.051s
$ time perl6 -e 'class Foo { has $.WHEN = now; }; for 1..1000000 { Foo.new }' real 1m12.477s user 1m8.057s sys 0m4.085s
This is a bit of a naive example, but the performance implications are pronounced enough to make me think its impractical.
Yes. Yes, that is. AlexDaniel's suggestion about a module is well taken, but if something like this can be boiled down to maybe 0.7s, would it be worthwhile? Does nqp have a native version of .now -- one that returns POSIX seconds? Might be better to benchmark that, instead.
from problem-solving.
Well, this is unexpected!
$ time perl6 -e 'use nqp; class Foo { }; for 1..1000000 { Foo.new }'
real 0m0.863s
user 0m0.944s
sys 0m0.061s
$ time perl6 -e 'use nqp; class Foo { has $.WHEN = nqp::time_n(); }; for 1..1000000 { Foo.new }'
real 0m0.770s
user 0m0.832s
sys 0m0.081s
(Caching?)
Of course, it really isn't that simple. This would occur at STORE, not new()
from problem-solving.
A DateTime
or Instant
is going to take longer to create than a Num
EDIT: actually I didn't notice it was faster
from problem-solving.
A
DateTime
orInstant
is going to take longer to create than aNum
Yes, but all I really need is a num. Yes, the original message was about DateTime, but posix_t is good enough and still accomplishes the goal.
EDIT: That was why it was unexpected =)
from problem-solving.
$ time perl6 -e 'use nqp; class Foo { }; for 1..1000000 { Foo.new }'
real 0m0.675s
user 0m0.700s
sys 0m0.056s
$ time perl6 -e 'use nqp; class Foo { has $.WHEN = nqp::time_n(); }; for 1..1000000 { Foo.new }'
real 0m5.542s
user 0m2.810s
sys 0m2.790s
from problem-solving.
We could do this all day. I guess I need to reboot and do this outside a VM, because this just doesn't make sense!
$ time perl6 -e 'use nqp; class Foo { }; for 1..10000000 { Foo.new }'
real 0m5.941s
user 0m6.019s
sys 0m0.052s
$ time perl6 -e 'use nqp; class Foo { has $.WHEN = nqp::time_n(); }; for 1..10000000 { Foo.new }'
real 0m4.874s
user 0m4.980s
sys 0m0.040s
Also, am doing this on Linux kernel v5.
$ uname -a
Linux cbwood-VirtualBox2 5.0.0-8-generic #9-Ubuntu SMP Tue Mar 12 21:58:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
from problem-solving.
@AlexDaniel I can look into cleaning up and publishing such a document, but I'm not immediately sure where to put it; any suggestions?
roast/docs/, and please take a look at this existing document: Policy For Implementation of New Features
from problem-solving.
To clarify, we will of course link to it from this repo too (from the issue template), but roast seems to be a more fitting place for it right now.
from problem-solving.
And to clarify even more, yes, such documents can be added to this repo too (by going through the whole process), but currently I don't see any good reason to do that. @jnthn if you feel like waiting for all reviewers to approve what's written in that upcoming document, then surely feel free to follow the process in this repo. Otherwise you can have a document that you'd be able to tweak at any time, which IMO makes more sense.
from problem-solving.
Well, module space it is. Thanks, everyone!
Any suggestions for naming?
from problem-solving.
Related Issues (20)
- Raku / Perl 6 books - CCR measures and beyond HOT 1
- Smartmatching to S/// is not a bug but a feature HOT 21
- Deprecation of flatmap is foggy and debatable HOT 6
- Wanted: new Raku Infrastructure jack-of-all-trades HOT 4
- Artistic License not a default on Github HOT 3
- `min` is presumptuous (on empty iterables) HOT 23
- Choose some precise (or rough) way to "adopt" modules in the Raku Module Adoption center HOT 5
- Handling of non-breaking spaces when splitting to words HOT 10
- Request to deprecate untwigiled attributes HOT 12
- `LEAVE` phaser fires when errorring in argument binding HOT 3
- Expand DEPRECATED functionality. HOT 6
- Feature request: snip counterpart for Str HOT 4
- Supply blocks may reorder flow of execution HOT 16
- Spectesting is a minefield HOT 28
- `next`, `last`, `redo` shouldn't fall through subroutines HOT 14
- Add :k option to min and max HOT 9
- LinkedIn does not recognize "Raku Developer" as a job title.
- Provide `sort` with `:k` adverb (returns ordinal index) HOT 5
- A way around "multi-level classification" HOT 1
- Trailing declarator docs semantics need to be revisited HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from problem-solving.