Comments (3)
The Instant
class itself is written with discrete units in mind, since they are faster to do calculations with and easier to reason about on platforms that have the concept of longs (all targets except JS). Internally, all instants hold their data as a Long
, so even if a constructor would accept a double, in order to adapt it to the common definition, it will still have to do the conversion, introducing the boxing. The only alternative would be to rewrite the JS implementation to not use longs at all, which is not an option since it would make it too different from the others, so this object creation in JavaScript is a necessary evil that shouldn't be circumvented.
I would instead suggest you define your own constructor by extending the companion object, just so at least you don't have to put a .toLong()
in every place where it is called:
@Suppress("NOTHING_TO_INLINE")
inline fun Instant.Companion.fromEpochMilliseconds(epochMilliseconds: Double) =
Instant.fromEpochMilliseconds(epochMilliseconds.toLong())
val time = Instant.fromEpochMilliseconds(12345678.9)
The real question is: have you noticed any significant performance issues in your project while using the library?
If so, are you sure it is related to the boxing?
from kotlinx-datetime.
Hello @Jadarma ,
thank you very much for that answer.
To answer your question: I have not checked whether there are performance issues while using the library.
We have heavily used timestamps of type Long in our project but replaced them all with Double values once we measured an performance impact. As far as I know only Int values are mapped to JavaScript Number values but they cannot be used due to their reduced range.
Since we do not want to go back to Long values I have to reevaluate for which part I will use kotlinx-datetime.
from kotlinx-datetime.
Hello, @ta834n. Glad I could help. Just a small correction: all numeric types except Long
are mapped to the JS Number
, see here.
from kotlinx-datetime.
Related Issues (20)
- API reference improvements HOT 1
- Consider adding parsing and formatting support for `kotlin.time.Duration`
- Provide custom formats for `DateTimePeriod`
- Introduce serializers corresponding to custom formats HOT 3
- Fix the ISO serializers omitting seconds when zero and emitting fractional parts in groups of three signs HOT 4
- Locale-aware formatting (but not parsing)
- Publish the design documents for datetime formats
- Update Kotlin version HOT 3
- ABI incompatible change on `kotlinx.datetime/LocalDateTime.Companion.parse` function in 0.6.0 release HOT 2
- Failed requirement on strange time zone HOT 1
- Potential improvements and input preservation in parsing and formatting error messages HOT 1
- Feature: building instant from DateTimeComponents HOT 8
- Feature: optional padding HOT 3
- InstantRange HOT 1
- Instant.parse(..) inconsistent between jvm and ios targets HOT 2
- Consider removing `Clock.asTimeSource` HOT 10
- [iOS] Fix parsing string without seconds HOT 1
- allTests Gradle task fails after adding v0.6.0-RC.2 dependency HOT 3
- Consider deprecating `DateTimePeriod.plus` and `DatePeriod.plus` HOT 4
- Consider moving `Instant` and `Clock` to the standard library
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 kotlinx-datetime.